opensc
NPCI secure-component & UPI Lite / Lite X wallet reimplementation
Loading...
Searching...
No Matches
json.h File Reference

Minimal JSON facade (backed by vendored parson), preserving key order like Android's org.json. More...

#include <stddef.h>
Include dependency graph for json.h:

Go to the source code of this file.

Typedefs

typedef struct lj_node lj_node
 Opaque JSON value (object, array, or scalar).
 

Enumerations

enum  lj_type {
  LJ_NULL , LJ_BOOL , LJ_NUM , LJ_STR ,
  LJ_ARR , LJ_OBJ
}
 JSON value kinds.
 

Functions

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.
 
lj_node * lj_new_obj (void)
 Creates an empty object node.
 
lj_node * lj_new_arr (void)
 Creates an empty array node.
 
void lj_free (lj_node *n)
 Frees a node and everything it owns (call only on a root).
 
lj_type lj_typeof (const lj_node *n)
 Returns the kind of n.
 
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).
 
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.
 
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.json).
 
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.
 
size_t lj_len (const lj_node *arr)
 Number of elements in an array (0 if not an array).
 
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).
 
void lj_append (lj_node *arr, lj_node *val)
 Appends val to an array, taking ownership of val.
 
const char * lj_as_str (const lj_node *n)
 Returns the scalar as text (string verbatim, number formatted, bool "true"/"false"), else NULL.
 
char * lj_dump (const lj_node *n)
 Serializes n compactly (no spaces, escaped strings) like org.json toString(); caller frees.
 

Detailed Description

Minimal JSON facade (backed by vendored parson), preserving key order like Android's org.json.