libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
JsonArray Class Reference

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
 

Detailed Description

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.

Member Function Documentation

◆ addFromVariant()

void JsonArray::addFromVariant ( const Variant val)
inline

Appends a value from a Variant, automatically selecting the JSON type.

Parameters
valThe Variant whose value and type determine the appended JSON element.

◆ forEach()

template<typename Func >
void JsonArray::forEach ( Func &&  func) const
inline

Iterates over all elements in the array.

Template Parameters
FuncCallable with signature void(const Variant &val).
Parameters
funcThe function to invoke for each element.

◆ getArray()

JsonArray JsonArray::getArray ( int  index,
Error err = nullptr 
) const
inline

Returns the nested JsonArray at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The nested JsonArray, or an empty array on failure.

◆ getBool()

bool JsonArray::getBool ( int  index,
Error err = nullptr 
) const
inline

Returns the boolean value at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The boolean value, or false on failure.

◆ getDouble()

double JsonArray::getDouble ( int  index,
Error err = nullptr 
) const
inline

Returns the double-precision floating-point value at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The double value, or 0.0 on failure.

◆ getInt()

int64_t JsonArray::getInt ( int  index,
Error err = nullptr 
) const
inline

Returns the signed 64-bit integer value at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The integer value, or 0 on failure.

◆ getObject()

JsonObject JsonArray::getObject ( int  index,
Error err = nullptr 
) const
inline

Returns the nested JsonObject at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The nested JsonObject, or an empty object on failure.

◆ getString()

String JsonArray::getString ( int  index,
Error err = nullptr 
) const
inline

Returns the string value at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The string value, or an empty String on failure.

◆ getUInt()

uint64_t JsonArray::getUInt ( int  index,
Error err = nullptr 
) const
inline

Returns the unsigned 64-bit integer value at the given index.

Parameters
indexThe zero-based element index.
errOptional error output.
Returns
The unsigned integer value, or 0 on failure.

◆ parse()

static JsonArray JsonArray::parse ( const String str,
Error err = nullptr 
)
inlinestatic

Parses a JSON array from a string.

Parameters
strThe JSON string to parse.
errOptional error output; set to Error::Invalid on failure.
Returns
The parsed JsonArray, or an empty array on failure.

◆ toString()

String JsonArray::toString ( unsigned int  indent = 0) const
inline

Serializes the array to a JSON string.

Parameters
indentNumber of spaces per indentation level. Zero produces compact output.
Returns
The serialized JSON string.

◆ valueIsArray()

bool JsonArray::valueIsArray ( int  index) const
inline

Returns true if the element at the given index is a JSON array.

Parameters
indexThe zero-based element index.

◆ valueIsNull()

bool JsonArray::valueIsNull ( int  index) const
inline

Returns true if the element at the given index is null.

Parameters
indexThe zero-based element index.

◆ valueIsObject()

bool JsonArray::valueIsObject ( int  index) const
inline

Returns true if the element at the given index is a JSON object.

Parameters
indexThe zero-based element index.

The documentation for this class was generated from the following file: