diff --git a/nlohmann::basicjson::size.md b/nlohmann::basicjson::size.md new file mode 100644 index 0000000..46f1bc7 --- /dev/null +++ b/nlohmann::basicjson::size.md @@ -0,0 +1,54 @@ +```cpp +size_type size() const; +``` + +## Description + +Returns the number of elements of a JSON value, i.e. `std::distance(begin(), end())`. + +## Return value + +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()` | + +## Parameter + +None. + +## Complexity + +Constant, as long as `ArrayType` and `ObjectType` satisfy the [Container concept](http://en.cppreference.com/w/cpp/concept/Container). + +## Exceptions + +None. The function's noexcept-specification is `noexcept`. + +## Example + +The following code uses empty to check if a `nlohmann::json` contains any elements: + +```cpp +#include +#include + +int main() +{ + nlohmann::json values {"string", true, 17, 23.42}; + + std::cout << "values contains " << values.size() << " elements.\n"; +} +``` + +Output: + +``` +values contains 4 elements. +``` \ No newline at end of file