libscipaper 1.0.x
Data Structures | Typedefs | Enumerations | Functions | Variables
Json Parsing API

Data Structures

struct  nx_json
 This struct discribes a parsed entry or file. More...
 

Typedefs

typedef int(* nx_json_unicode_encoder) (unsigned int codepoint, char *p, char **endp)
 this typdef descibes a function that takes a Unicode codepoint and writes corresponding encoded value into buffer pointed by p.
 

Enumerations

enum  nx_json_type {
  NX_JSON_NULL , NX_JSON_OBJECT , NX_JSON_ARRAY , NX_JSON_STRING ,
  NX_JSON_INTEGER , NX_JSON_DOUBLE , NX_JSON_BOOL
}
 This enum is used in nx_json to discribe what type a given json entry has. More...
 

Functions

const nx_jsonnx_json_parse (char *text, nx_json_unicode_encoder encoder)
 This struct discribes a parsed entry or file.
 
const nx_jsonnx_json_parse_utf8 (char *text)
 This is shortcut for nx_json_parse(text, nx_json_unicode_to_utf8) where nx_json_unicode_to_utf8 is unicode to UTF-8 encoder provided by NXJSON.
 
void nx_json_free (const nx_json *js)
 Frees a nx_json struct parsed by nx_json_parse()
 
const nx_jsonnx_json_get (const nx_json *json, const char *key)
 Gets object's property or child by key.
 
const nx_jsonnx_json_item (const nx_json *json, int idx)
 Gets an array element by index This function never returns NULL or fails for any reason.
 

Variables

nx_json_unicode_encoder nx_json_unicode_to_utf8
 

Detailed Description

Typedef Documentation

◆ nx_json_unicode_encoder

typedef int(* nx_json_unicode_encoder) (unsigned int codepoint, char *p, char **endp)

this typdef descibes a function that takes a Unicode codepoint and writes corresponding encoded value into buffer pointed by p.

It should store pointer to the end of encoded value into *endp. The function should return 1 on success and 0 on error. Number of bytes written must not exceed 6.

Enumeration Type Documentation

◆ nx_json_type

This enum is used in nx_json to discribe what type a given json entry has.

Enumerator
NX_JSON_NULL 

this is null value

NX_JSON_OBJECT 

this is an object; properties can be found in child nodes

NX_JSON_ARRAY 

this is an array; items can be found in child nodes

NX_JSON_STRING 

this is a string; value can be found in text_value field

NX_JSON_INTEGER 

this is an integer; value can be found in int_value field

NX_JSON_DOUBLE 

this is a double; value can be found in dbl_value field

NX_JSON_BOOL 

this is a boolean; value can be found in int_value field

Function Documentation

◆ nx_json_get()

const nx_json * nx_json_get ( const nx_json * json,
const char * key )

Gets object's property or child by key.

This function never returns NULL or fails for any reason. If a parse error occures or the requested key dosent exist a object of type NX_JSON_NULL is returned.

Parameters
jsonparent json object
keykey of the child or property you want
Returns
a nx_json struct discribeing the array element. Do not free this, its lifetime is equal to the top level nx_json object returned by nx_json_parse()

◆ nx_json_item()

const nx_json * nx_json_item ( const nx_json * json,
int idx )

Gets an array element by index This function never returns NULL or fails for any reason.

If a parse error occures or the requested key dosent exist a object of type NX_JSON_NULL is returned.

Parameters
jsonThe array
idxThe index where you want to get the object out of the array
Returns
a nx_json struct discribeing the array element. Do not free this, its lifetime is equal to the top level nx_json object returned by nx_json_parse()

◆ nx_json_parse()

const nx_json * nx_json_parse ( char * text,
nx_json_unicode_encoder encoder )

This struct discribes a parsed entry or file.

Parameters
texta text string containing the json to be parsed
encodera function of type nx_json_unicode_encoder
Returns
parsed top level json object as a nx_json struct, to be freed with nx_json_free() or NULL if there was a parse error

◆ nx_json_parse_utf8()

const nx_json * nx_json_parse_utf8 ( char * text)

This is shortcut for nx_json_parse(text, nx_json_unicode_to_utf8) where nx_json_unicode_to_utf8 is unicode to UTF-8 encoder provided by NXJSON.

Parameters
texta text string containing the json to be parsed
Returns
parsed top level json object as a nx_json struct, to be freed with nx_json_free() or NULL if there was a parse error