json
Classes
| Name | Description |
|---|---|
Configuration | JSON configuration file |
ISerializable | Abstract interface for JSON-serializable objects. |
Typedefs
| Return | Name | Description |
|---|---|---|
nlohmann::json | Value | Primary JSON value type used throughout the library. |
Value
using Value = nlohmann::jsonDefined in src/json/include/icy/json/json.h:40
Primary JSON value type used throughout the library.
Functions
| Return | Name | Description |
|---|---|---|
bool | serialize inline | Serializes pObj to a pretty-printed JSON string. |
bool | deserialize inline | Deserializes pObj from a JSON string. |
void | loadFile inline | Load a JSON file into a value. Throws on missing file or parse error. |
void | saveFile inline | Save a JSON value to a file. Throws on write error. |
void | assertMember inline | Assert that a required member exists. Throws if missing. |
void | countNestedKeys inline | Count how many nested objects contain the given key. |
bool | hasNestedKey inline | Return true if any nested object contains the given key. |
bool | findNestedObjectWithProperty inline | Find a nested object whose property matches the given key/value. |
serialize
inline
inline bool serialize(ISerializable * pObj, std::string & output)Defined in src/json/include/icy/json/iserializable.h:43
Serializes pObj to a pretty-printed JSON string.
Returns
true on success, false if pObj is null.
Parameters
| Parameter | Type | Description |
|---|---|---|
pObj | ISerializable * | Object to serialize; must not be null. |
output | std::string & | Receives the 4-space indented JSON string. |
deserialize
inline
inline bool deserialize(ISerializable * pObj, std::string & input)Defined in src/json/include/icy/json/iserializable.h:59
Deserializes pObj from a JSON string.
Returns
true on success, false if pObj is null or parsing fails.
Parameters
| Parameter | Type | Description |
|---|---|---|
pObj | ISerializable * | Object to populate; must not be null. |
input | std::string & | JSON string to parse. |
loadFile
inline
inline void loadFile(const std::string & path, json::Value & root)Defined in src/json/include/icy/json/json.h:44
Load a JSON file into a value. Throws on missing file or parse error.
saveFile
inline
inline void saveFile(const std::string & path, const json::Value & root, int indent = 4)Defined in src/json/include/icy/json/json.h:56
Save a JSON value to a file. Throws on write error.
assertMember
inline
inline void assertMember(const json::Value & root, const std::string & name)Defined in src/json/include/icy/json/json.h:71
Assert that a required member exists. Throws if missing.
countNestedKeys
inline
inline void countNestedKeys(const json::Value & root, const std::string & key, int & count)Defined in src/json/include/icy/json/json.h:79
Count how many nested objects contain the given key.
hasNestedKey
inline
inline bool hasNestedKey(const json::Value & root, const std::string & key)Defined in src/json/include/icy/json/json.h:92
Return true if any nested object contains the given key.
findNestedObjectWithProperty
inline
inline bool findNestedObjectWithProperty(json::Value & root, json::Value *& result, std::string_view key, std::string_view value, bool partial = true, int index = 0)Defined in src/json/include/icy/json/json.h:113
Find a nested object whose property matches the given key/value.
Key or value may be empty for wildcard matching. If partial is true, substring matches are accepted for string values. The index parameter selects the Nth match (0 = first).
Returns true if found, with result pointing to the matching object.
