File syn_json_read.c¶
FileList > src > syntropic > util > syn_json_read.c
Go to the source code of this file
Minimal JSON reader — in-place tokenizer.
#include "../util/syn_assert.h"#include "syn_json_read.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| const SYN_JsonToken * | syn_json_find (const SYN_JsonReader * r, const char * key) Find a token by key name. |
| bool | syn_json_get_bool (const SYN_JsonReader * r, const char * key, bool * out) Get a boolean value by key. |
| bool | syn_json_get_int (const SYN_JsonReader * r, const char * key, int32_t * out) Get an integer value by key. |
| bool | syn_json_get_str (const SYN_JsonReader * r, const char * key, char * out, size_t out_sz) Get a string value by key. |
| SYN_JsonType | syn_json_get_type (const SYN_JsonReader * r, const char * key) Get the type of a value by key. |
| bool | syn_json_is_null (const SYN_JsonReader * r, const char * key) Check if a key exists and is null. |
| bool | syn_json_parse (SYN_JsonReader * r, char * json, size_t len) Parse a JSON string in-place. |
Public Static Functions¶
| Type | Name |
|---|---|
| int32_t | parse_int (const char * s) Parse a signed integer from a string. |
| char * | parse_object (SYN_JsonReader * r, char * p, const char * end, uint8_t depth) Recursive JSON object parser. |
| char * | parse_string (char * p, const char * end, const char ** out) Parse a JSON string starting at p. |
| char * | skip_value (char * p, const char * end) Skip a JSON value (any type). |
| char * | skip_ws (char * p, const char * end) Skip whitespace. |
Public Functions Documentation¶
function syn_json_find¶
Find a token by key name.
Use dot notation for nested keys: "wifi.ssid"
Parameters:
rReader.keyKey to find.
Returns:
Pointer to token, or NULL if not found.
function syn_json_get_bool¶
Get a boolean value by key.
Parameters:
rReader.keyKey to find.outOutput value.
Returns:
true if key found and value is a boolean.
function syn_json_get_int¶
Get an integer value by key.
Parameters:
rReader.keyKey to find.outOutput value.
Returns:
true if key found and value is a number.
function syn_json_get_str¶
Get a string value by key.
Parameters:
rReader.keyKey to find.outOutput buffer for the string.out_szBuffer capacity.
Returns:
true if key found and value is a string.
function syn_json_get_type¶
Get the type of a value by key.
Parameters:
rReader.keyKey to find.
Returns:
SYN_JsonType, or SYN_JSON_NONE if not found.
function syn_json_is_null¶
Check if a key exists and is null.
Parameters:
rReader.keyKey to find.
Returns:
true if key exists and value is null.
function syn_json_parse¶
Parse a JSON string in-place.
Tokenizes the JSON into key-value pairs. Modifies the input buffer (inserts null terminators at string boundaries).
Parameters:
rReader instance.jsonJSON string (will be modified).lenLength of JSON string.
Returns:
true if parsing succeeded.
Public Static Functions Documentation¶
function parse_int¶
Parse a signed integer from a string.
Parameters:
sInput string.
Returns:
Parsed value.
function parse_object¶
Recursive JSON object parser.
Tokenizes key-value pairs at the given depth.
Parameters:
rJSON reader instance.pCurrent position.endEnd of buffer.depthCurrent nesting depth.
Returns:
Pointer past the object.
function parse_string¶
Parse a JSON string starting at p.
Must point to opening '"'. Null-terminates in-place.
Parameters:
pCurrent position (at opening '"').endEnd of buffer.out[out] Start of the string content.
Returns:
Pointer past the closing '"', or NULL on error.
function skip_value¶
Skip a JSON value (any type).
Parameters:
pCurrent position.endEnd of buffer.
Returns:
Pointer past the value.
function skip_ws¶
Skip whitespace.
Parameters:
pCurrent position.endEnd of buffer.
Returns:
Pointer to next non-whitespace char.
The documentation for this class was generated from the following file src/syntropic/util/syn_json_read.c