nlohmann::basic_json::size - renxiaobo27/json GitHub Wiki
size_type size() const;Returns the number of elements of a JSON value, i.e. std::distance(begin(), end()).
The return value depends on the different value types and is defined as follows:
| Value type | return value |
|---|---|
| null | 0 |
| boolean | 1 |
| string | 1 |
| number | 1 |
| object | ObjectType::size() |
| array | ArrayType::size() |
None.
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 values {"string", true, 17, 23.42};
std::cout << "values contains " << values.size() << " elements.\n";
}Output:
values contains 4 elements.