|
CX Framework
Cross-platform C utility framework
|
Typedefs | |
| typedef void(* | jsonParseCB) (JSONParseEvent *ev, void *userdata) |
Functions | |
| bool | jsonParse (StreamBuffer *sb, jsonParseCB callback, void *userdata) |
| SSDNode * | jsonParseTree (StreamBuffer *sb) |
| SSDNode * | jsonParseTreeCustom (StreamBuffer *sb, SSDTree *tree) |
| SSDNode * | jsonTreeFromString (strref str) |
Parse JSON from stream buffers into SSD trees or via callbacks.
The JSON parser supports two modes:
Event-Driven Parsing (jsonParse): Invokes a callback for each JSON element as it's parsed. Suitable for streaming large files or custom data processing.
Tree Parsing (jsonParseTree): Fully loads JSON into an SSD tree for convenient random access and manipulation.
Both modes require a stream buffer in PULL mode.
Example (event-driven):
Example (tree parsing):
| typedef void(* jsonParseCB) (JSONParseEvent *ev, void *userdata) |
void (*jsonParseCB)(JSONParseEvent *ev, void *userdata)
Callback function type for event-driven JSON parsing.
This callback is invoked for each JSON element as it's parsed. The JSONParseEvent contains the event type, current parser context, and event-specific data.
IMPORTANT: String data in events (strData) is only valid during the callback. Copy the string if you need to retain it.
| ev | Parse event containing type, context, and data |
| userdata | User context pointer passed to jsonParse() |
Definition at line 68 of file jsonparse.h.
| bool jsonParse | ( | StreamBuffer * | sb, |
| jsonParseCB | callback, | ||
| void * | userdata | ||
| ) |
bool jsonParse(StreamBuffer *sb, jsonParseCB callback, void *userdata)
Parses JSON data using an event-driven callback interface.
The stream buffer must be configured in PULL mode before calling this function. The parser invokes the callback for each JSON element: objects, arrays, strings, numbers, booleans, and null values.
This mode is ideal for:
IMPORTANT: The stream buffer is invalidated after this call.
| sb | Stream buffer in pull mode (invalidated after call) |
| callback | Function to invoke for each parse event |
| userdata | User context passed to callbacks |
Example:
| SSDNode * jsonParseTree | ( | StreamBuffer * | sb | ) |
SSDNode *jsonParseTree(StreamBuffer *sb)
Parses JSON data into an SSD tree.
Fully loads the JSON data into a semi-structured data tree for convenient access and manipulation. The returned tree root must be released with objRelease() when done.
The stream buffer must be configured in PULL mode before calling this function.
IMPORTANT: The stream buffer is invalidated after this call.
| sb | Stream buffer in pull mode (invalidated after call) |
Example:
| SSDNode * jsonParseTreeCustom | ( | StreamBuffer * | sb, |
| SSDTree * | tree | ||
| ) |
SSDNode *jsonParseTreeCustom(StreamBuffer *sb, SSDTree *tree)
Parses JSON data into an existing SSD tree.
Like jsonParseTree(), but allows using a pre-existing SSDTree for node allocation. Useful when you need to control tree properties or maintain multiple related trees.
IMPORTANT: The stream buffer is invalidated after this call.
| sb | Stream buffer in pull mode (invalidated after call) |
| tree | Existing SSD tree to allocate nodes from (optional, NULL creates new tree) |
| SSDNode * jsonTreeFromString | ( | strref | str | ) |
SSDNode *jsonTreeFromString(strref str)
Parses JSON data from a string into an SSD tree.
Convenience function that internally creates a stream buffer, parses the JSON string, and returns the resulting tree. Equivalent to manually setting up a stream buffer with sbufStrPRegisterPull() and calling jsonParseTree().
| str | JSON string to parse |
Example: