Table of Contents
- JSON: a thin public wrapper over cJSON
- Types
- Functions
- Types Documentation
- Functions Documentation
- function n_json_string_dup
- function n_json_string
- function n_json_parse_len
- function n_json_parse_file
- function n_json_parse
- function n_json_number
- function n_json_next
- function n_json_key
- function n_json_is_string
- function n_json_is_object
- function n_json_is_number
- function n_json_is_array
- function n_json_int
- function n_json_get
- function n_json_free
- function n_json_first
- function n_json_bool
- function n_json_as_string
- function n_json_as_number
- function n_json_as_bool
- function n_json_array_size
- function n_json_array_at
JSON: a thin public wrapper over cJSON
Types
| Name | |
|---|---|
| typedef struct N_JSON | N_JSON Opaque JSON node (a cJSON node under the hood). |
Functions
| Name | |
|---|---|
| char * | n_json_string_dup(const N_JSON * obj, const char * key) Duplicate a string member (caller frees), or NULL when absent. |
| const char * | n_json_string(const N_JSON * obj, const char * key, const char * dflt) Get a string member, or a default when absent/not a string. |
| N_JSON * | n_json_parse_len(const char * text, size_t len) Parse a JSON document from a buffer that need not be NUL-terminated. |
| N_JSON * | n_json_parse_file(const char * path) Parse a JSON document from a file. |
| N_JSON * | n_json_parse(const char * text) Parse a JSON document from a NUL-terminated string. |
| double | n_json_number(const N_JSON * obj, const char * key, double dflt) Get a numeric member as a double, or a default when absent/not a number. |
| N_JSON * | n_json_next(const N_JSON * v) Next sibling of a node inside its array or object. |
| const char * | n_json_key(const N_JSON * v) Member name of a node that is a member of an object. |
| int | n_json_is_string(const N_JSON * v) Report whether a node is a JSON string. |
| int | n_json_is_object(const N_JSON * v) Report whether a node is a JSON object. |
| int | n_json_is_number(const N_JSON * v) Report whether a node is a JSON number. |
| int | n_json_is_array(const N_JSON * v) Report whether a node is a JSON array. |
| long | n_json_int(const N_JSON * obj, const char * key, long dflt) Get a numeric member as a long, or a default when absent/not a number. |
| N_JSON * | n_json_get(const N_JSON * obj, const char * key) Get a child member of an object by key (case-sensitive). |
| void | n_json_free(N_JSON ** root) Free a JSON tree and NULL the caller's pointer. |
| N_JSON * | n_json_first(const N_JSON * v) First child of an array or object, to walk it with n_json_next(). |
| int | n_json_bool(const N_JSON * obj, const char * key, int dflt) Get a boolean member, or a default when absent/not a boolean. |
| const char * | n_json_as_string(const N_JSON * v, const char * dflt) Get the string value of a node itself (e.g. |
| int | n_json_as_number(const N_JSON * v, double * out) Get the numeric value of a node itself (e.g. |
| int | n_json_as_bool(const N_JSON * v, int dflt) Get the boolean value of a node itself. |
| size_t | n_json_array_size(const N_JSON * arr) Number of elements in an array node. |
| N_JSON * | n_json_array_at(const N_JSON * arr, size_t i) Get an array element by index. |
Types Documentation
typedef N_JSON
typedef struct N_JSON N_JSON;
Opaque JSON node (a cJSON node under the hood).
Functions Documentation
function n_json_string_dup
char * n_json_string_dup(
const N_JSON * obj,
const char * key
)
Duplicate a string member (caller frees), or NULL when absent.
Parameters:
- obj The object node, or NULL.
- key The member name.
Return: A malloc'd copy of the string value, or NULL.
function n_json_string
const char * n_json_string(
const N_JSON * obj,
const char * key,
const char * dflt
)
Get a string member, or a default when absent/not a string.
Parameters:
- obj The object node, or NULL.
- key The member name.
- dflt Value returned when the member is missing or not a string.
Return: A borrowed string pointer, or dflt.
function n_json_parse_len
N_JSON * n_json_parse_len(
const char * text,
size_t len
)
Parse a JSON document from a buffer that need not be NUL-terminated.
Parameters:
- text The JSON text. NULL returns NULL.
- len Number of bytes of
textto parse.
Return: A new root node (free with n_json_free), or NULL on a parse error.
function n_json_parse_file
N_JSON * n_json_parse_file(
const char * path
)
Parse a JSON document from a file.
Parameters:
- path Path to the JSON file. NULL returns NULL.
Return: A new root node (free with n_json_free), or NULL on read/parse error.
function n_json_parse
N_JSON * n_json_parse(
const char * text
)
Parse a JSON document from a NUL-terminated string.
Parameters:
- text The JSON text. NULL returns NULL.
Return: A new root node (free with n_json_free), or NULL on a parse error.
function n_json_number
double n_json_number(
const N_JSON * obj,
const char * key,
double dflt
)
Get a numeric member as a double, or a default when absent/not a number.
Parameters:
- obj The object node, or NULL.
- key The member name.
- dflt Value returned when the member is missing or not a number.
Return: The value, or dflt.
function n_json_next
N_JSON * n_json_next(
const N_JSON * v
)
Next sibling of a node inside its array or object.
Parameters:
- v The node, or NULL.
Return: The next sibling (borrowed), or NULL after the last one.
function n_json_key
const char * n_json_key(
const N_JSON * v
)
Member name of a node that is a member of an object.
Parameters:
- v The node, or NULL.
Return: The borrowed key, or NULL when v is not an object member.
function n_json_is_string
int n_json_is_string(
const N_JSON * v
)
Report whether a node is a JSON string.
Parameters:
- v The node, or NULL.
Return: 1 when v is a string, 0 otherwise.
function n_json_is_object
int n_json_is_object(
const N_JSON * v
)
Report whether a node is a JSON object.
Parameters:
- v The node, or NULL.
Return: 1 when v is an object, 0 otherwise.
function n_json_is_number
int n_json_is_number(
const N_JSON * v
)
Report whether a node is a JSON number.
Parameters:
- v The node, or NULL.
Return: 1 when v is a number, 0 otherwise.
function n_json_is_array
int n_json_is_array(
const N_JSON * v
)
Report whether a node is a JSON array.
Parameters:
- v The node, or NULL.
Return: 1 when v is an array, 0 otherwise.
function n_json_int
long n_json_int(
const N_JSON * obj,
const char * key,
long dflt
)
Get a numeric member as a long, or a default when absent/not a number.
Parameters:
- obj The object node, or NULL.
- key The member name.
- dflt Value returned when the member is missing or not a number.
Return: The integer value, or dflt.
function n_json_get
N_JSON * n_json_get(
const N_JSON * obj,
const char * key
)
Get a child member of an object by key (case-sensitive).
Parameters:
- obj The object node, or NULL.
- key The member name. NULL returns NULL.
Return: The child node (borrowed), or NULL when absent.
function n_json_free
void n_json_free(
N_JSON ** root
)
Free a JSON tree and NULL the caller's pointer.
Parameters:
- root Address of the root pointer. May be NULL or point to NULL.
function n_json_first
N_JSON * n_json_first(
const N_JSON * v
)
First child of an array or object, to walk it with n_json_next().
Parameters:
- v The array or object node, or NULL.
Return: The first child (borrowed), or NULL when empty or not a container.
Walking with n_json_first()/n_json_next() is linear in the number of children, while calling n_json_array_at() for every index is quadratic.
function n_json_bool
int n_json_bool(
const N_JSON * obj,
const char * key,
int dflt
)
Get a boolean member, or a default when absent/not a boolean.
Parameters:
- obj The object node, or NULL.
- key The member name.
- dflt Value returned when the member is missing or not a boolean.
Return: 1 or 0, or dflt.
function n_json_as_string
const char * n_json_as_string(
const N_JSON * v,
const char * dflt
)
Get the string value of a node itself (e.g.
Parameters:
- v The node, or NULL.
- dflt Value returned when
vis not a string.
Return: A borrowed string pointer, or dflt.
an array element).
function n_json_as_number
int n_json_as_number(
const N_JSON * v,
double * out
)
Get the numeric value of a node itself (e.g.
Parameters:
- v The node, or NULL.
- out Receives the value when
vis a number. May be NULL.
Return: 1 when v is a number, 0 otherwise (out untouched).
an array element).
function n_json_as_bool
int n_json_as_bool(
const N_JSON * v,
int dflt
)
Get the boolean value of a node itself.
Parameters:
- v The node, or NULL.
- dflt Value returned when
vis not a boolean.
Return: 1 or 0, or dflt.
function n_json_array_size
size_t n_json_array_size(
const N_JSON * arr
)
Number of elements in an array node.
Parameters:
- arr The array node, or NULL.
Return: The element count, or 0.
function n_json_array_at
N_JSON * n_json_array_at(
const N_JSON * arr,
size_t i
)
Get an array element by index.
Parameters:
- arr The array node, or NULL.
- i Zero-based index.
Return: The element (borrowed), or NULL when out of range.
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB