10typedef enum { LJ_NULL, LJ_BOOL, LJ_NUM, LJ_STR, LJ_ARR, LJ_OBJ }
lj_type;
lj_node * lj_new_obj(void)
Creates an empty object node.
void lj_put_str(lj_node *obj, const char *key, const char *val)
Sets key to a string; updates in place if present, preserving position (matches org....
void lj_free(lj_node *n)
Frees a node and everything it owns (call only on a root).
lj_type
JSON value kinds.
Definition json.h:10
void lj_put_node(lj_node *obj, const char *key, lj_node *val)
Sets key to val, taking ownership of val; updates in place if present.
lj_node * lj_new_arr(void)
Creates an empty array node.
const lj_node * lj_at(const lj_node *arr, size_t i)
Element i of an array, or NULL if out of range / not an array (borrowed).
const char * lj_as_str(const lj_node *n)
Returns the scalar as text (string verbatim, number formatted, bool "true"/"false"),...
void lj_append(lj_node *arr, lj_node *val)
Appends val to an array, taking ownership of val.
char * lj_dump(const lj_node *n)
Serializes n compactly (no spaces, escaped strings) like org.json toString(); caller frees.
const lj_node * lj_get(const lj_node *obj, const char *key)
Returns the value at key, or NULL if absent / not an object (borrowed).
struct lj_node lj_node
Opaque JSON value (object, array, or scalar).
Definition json.h:13
lj_type lj_typeof(const lj_node *n)
Returns the kind of n.
lj_node * lj_parse(const char *text, size_t len)
Parses len bytes of JSON text; returns a root node (free with lj_free) or NULL on error.
const char * lj_get_str(const lj_node *obj, const char *key, const char *dflt)
Returns the string value at key, or dflt if absent / not a string.
size_t lj_len(const lj_node *arr)
Number of elements in an array (0 if not an array).