JSON array container wrapping nlohmann::json. More...
#include <json.h>
Public Types | |
| using | Ptr = SharedPtr< JsonArray > |
| Shared pointer type for JsonArray. | |
Public Member Functions | |
| JsonArray () | |
| Constructs an empty JSON array. | |
| int | size () const |
| Returns the number of elements in the array. | |
| bool | isValid () const |
| Returns true if the array contains at least one element. | |
| bool | valueIsNull (int index) const |
| Returns true if the element at the given index is null. | |
| bool | valueIsObject (int index) const |
| Returns true if the element at the given index is a JSON object. | |
| bool | valueIsArray (int index) const |
| Returns true if the element at the given index is a JSON array. | |
| bool | getBool (int index, Error *err=nullptr) const |
| Returns the boolean value at the given index. | |
| int64_t | getInt (int index, Error *err=nullptr) const |
| Returns the signed 64-bit integer value at the given index. | |
| uint64_t | getUInt (int index, Error *err=nullptr) const |
| Returns the unsigned 64-bit integer value at the given index. | |
| double | getDouble (int index, Error *err=nullptr) const |
| Returns the double-precision floating-point value at the given index. | |
| String | getString (int index, Error *err=nullptr) const |
| Returns the string value at the given index. | |
| JsonObject | getObject (int index, Error *err=nullptr) const |
| Returns the nested JsonObject at the given index. | |
| JsonArray | getArray (int index, Error *err=nullptr) const |
| Returns the nested JsonArray at the given index. | |
| String | toString (unsigned int indent=0) const |
| Serializes the array to a JSON string. | |
| void | clear () |
| Removes all elements from the array. | |
| void | addNull () |
| Appends a null value to the array. | |
| void | add (const JsonObject &val) |
| Appends a JsonObject to the array. | |
| void | add (const JsonArray &val) |
| Appends a JsonArray to the array. | |
| void | add (bool val) |
| Appends a boolean value to the array. | |
| void | add (int val) |
| Appends an int value to the array. | |
| void | add (unsigned int val) |
| Appends an unsigned int value to the array. | |
| void | add (int64_t val) |
| Appends a signed 64-bit integer to the array. | |
| void | add (uint64_t val) |
| Appends an unsigned 64-bit integer to the array. | |
| void | add (float val) |
| Appends a float value to the array. | |
| void | add (double val) |
| Appends a double value to the array. | |
| void | add (const char *val) |
| Appends a C-string value to the array. | |
| void | add (const String &val) |
| Appends a String value to the array. | |
| void | add (const UUID &val) |
| Appends a UUID (stored as its string representation) to the array. | |
| void | addFromVariant (const Variant &val) |
| Appends a value from a Variant, automatically selecting the JSON type. | |
| template<typename Func > | |
| void | forEach (Func &&func) const |
| Iterates over all elements in the array. | |
Static Public Member Functions | |
| static JsonArray | parse (const String &str, Error *err=nullptr) |
| Parses a JSON array from a string. | |
Friends | |
| class | JsonObject |
JSON array container wrapping nlohmann::json.
Provides a type-safe interface for building and querying JSON arrays. Elements are accessed by index with typed getters that perform safe conversions. Supports nesting via JsonObject and JsonArray elements.
Appends a value from a Variant, automatically selecting the JSON type.
| val | The Variant whose value and type determine the appended JSON element. |
Iterates over all elements in the array.
| Func | Callable with signature void(const Variant &val). |
| func | The function to invoke for each element. |
Returns the boolean value at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
Returns the double-precision floating-point value at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
Returns the signed 64-bit integer value at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
|
inline |
Returns the nested JsonObject at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
Returns the string value at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
Returns the unsigned 64-bit integer value at the given index.
| index | The zero-based element index. |
| err | Optional error output. |
Parses a JSON array from a string.
| str | The JSON string to parse. |
| err | Optional error output; set to Error::Invalid on failure. |
Serializes the array to a JSON string.
| indent | Number of spaces per indentation level. Zero produces compact output. |
|
inline |
Returns true if the element at the given index is a JSON array.
| index | The zero-based element index. |
|
inline |
Returns true if the element at the given index is null.
| index | The zero-based element index. |
|
inline |
Returns true if the element at the given index is a JSON object.
| index | The zero-based element index. |