nlohmann::basic_json::empty - renxiaobo27/json GitHub Wiki
bool empty() const;Checks if a JSON value has no elements, i.e. whether begin() == end().
None.
The return value depends on the different value types and is defined as follows:
| Value type | return value |
|---|---|
| null | true |
| boolean | false |
| string | false |
| number | false |
| object | ObjectType::empty() |
| array | ArrayType::empty() |
Constant, as long as ArrayType and ObjectType satisfy the Container concept.
None. The function's noexcept-specification is noexcept.
The following code uses empty to check if a nlohmann::json contains any elements:
#include <iostream>
#include <json.hpp>
int main()
{
nlohmann::json numbers;
std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
numbers.push_back(42);
numbers.push_back(13317);
std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}Output:
Initially, numbers.empty(): 1
After adding elements, numbers.empty(): 0