Skip to main content

Json

The Json class provides a flexible and efficient interface for working with Json data. It supports a wide range of functionalities for creating, manipulating, and querying Json data, including handling Json objects, arrays, strings, numbers, booleans, and more. This class is designed to work with nested structures and offers various methods for loading, saving, and editing Json content.

#include <format/TellusimJson.h>

Constructors

Json()
explicit Json(Type type)
explicit Json(const char *name, Type type = TypeUnknown)
explicit Json(const String &name, Type type = TypeUnknown)
Json(Json *parent, const char *name, Type type = TypeUnknown)
Json(Json *parent, const String &name, Type type = TypeUnknown)

Methods

Clear json.

void clear()

Create json.

bool create(const char *str, size_t size = 0, bool owner = false)
bool create(const String &str, size_t size = 0, bool owner = false)

Load json.

bool load(const char *name)
bool load(const String &name)
bool load(Stream &stream)

Save json.

bool save(const char *name, bool compact = false) const
bool save(const String &name, bool compact = false) const
bool save(Stream &stream, bool compact = false) const

Json root.

const Json getRoot() const
Json getRoot()

Json parent.

uint32_t setParent(Json &parent, bool check = true)
const Json getParent() const
Json getParent()

Json children.

Json addChild(const char *name, Type type = TypeUnknown, bool check = true)
uint32_t addChild(Json &child, bool check = true)
bool removeChild(Json &child)
void releaseChildren()
uint32_t findChild(const char *name) const
bool isChild(const char *name) const
const Json getChild(const char *name) const
Json getChild(const char *name)
uint32_t getNumChildren() const
const Array<Json> getChildren() const
Array<Json> getChildren()
const Json getChild(uint32_t index) const
Json getChild(uint32_t index)

Json path name.

String getPathName() const

Json name.

void setName(const char *name)
void setName(const String &name)
String getName() const

Json type.

void setType(Type type)
Type getType() const
static const char *getTypeName(Type type)
const char *getTypeName() const
bool isUnknown() const
bool isNull() const
bool isBool() const
bool isNumber() const
bool isString() const
bool isObject() const
bool isArray() const

Json data.

void setData(bool value)
void setData(int32_t value, uint32_t radix = 10)
void setData(uint32_t value, uint32_t radix = 10)
void setData(uint64_t value, uint32_t radix = 10)
void setData(float32_t value, uint32_t digits = 6, bool compact = true, bool exponent = true)
void setData(float64_t value, uint32_t digits = 12, bool compact = true, bool exponent = true)
void setData(const char *value)
void setData(const String &value)
template<> Json setData(const char *name, Type value, Json::Type type = TypeUnknown)
String getData() const
bool getDataBool() const
int32_t getDatai32(uint32_t radix = 10) const
uint32_t getDatau32(uint32_t radix = 10) const
uint64_t getDatau64(uint32_t radix = 10) const
float32_t getDataf32() const
float64_t getDataf64() const
String getNumber() const
String getString() const
bool getData(const char *name, bool value) const
int32_t getData(const char *name, int32_t value, uint32_t radix = 10) const
uint32_t getData(const char *name, uint32_t value, uint32_t radix = 10) const
uint64_t getData(const char *name, uint64_t value, uint32_t radix = 10) const
float32_t getData(const char *name, float32_t value) const
float64_t getData(const char *name, float64_t value) const
String getData(const char *name, const String &value = String::null) const
TypeNameDescription
uint32_tradixThe decimal number radix (use 16 for hexadecimal numbers).
uint32_tdigitsThe number of digits in the floating-point representation.
boolcompactRemove redundant zeros at the end of the number.
boolexponentUse exponent representation.

Json array data.

void setData(const char **values, uint32_t size)
void setData(const String *values, uint32_t size)
void setData(const int32_t *values, uint32_t size, uint32_t radix = 10)
void setData(const uint32_t *values, uint32_t size, uint32_t radix = 10)
void setData(const float32_t *values, uint32_t size, uint32_t digits = 6, bool compact = true, bool exponent = true)
void setData(const float64_t *values, uint32_t size, uint32_t digits = 12, bool compact = true, bool exponent = true)
template<> Json setData(const char *name, Type *values, uint32_t size, Json::Type type = TypeUnknown)
template<> void setData(const Array<Type> &values)
template<> void setData(const char *name, const Array<Type> &values)
uint32_t getData(String *values, uint32_t size) const
uint32_t getData(int32_t *values, uint32_t size, uint32_t radix = 10) const
uint32_t getData(uint32_t *values, uint32_t size, uint32_t radix = 10) const
uint32_t getData(float32_t *values, uint32_t size) const
uint32_t getData(float64_t *values, uint32_t size) const
template<> uint32_t getData(const char *name, Type *values, uint32_t size) const
template<> uint32_t getData(Array<Type> &values) const
template<> uint32_t getData(const char *name, Array<Type> &values) const
TypeNameDescription
uint32_tradixThe decimal number radix (use 16 for hexadecimal numbers).
uint32_tdigitsThe number of digits in the floating-point representation.
boolcompactRemove redundant zeros at the end of the number.
boolexponentUse exponent representation.

Enums

Type

Json types.

NameValue
TypeUnknown0
TypeNull1
TypeBool2
TypeNumber3
TypeString4
TypeObject5
TypeArray6
NumTypes7