Home --> Documentations --> PJLIB-UTIL Reference

Data Structures | Typedefs | Enumerations | Functions
JSON Writer and Loader

Data Structures

struct  pj_json_list
 
struct  pj_json_elem
 
struct  pj_json_err_info
 

Typedefs

typedef pj_status_t(* pj_json_writer )(const char *s, unsigned size, void *user_data)
 

Enumerations

enum  pj_json_val_type {
  PJ_JSON_VAL_NULL, PJ_JSON_VAL_BOOL, PJ_JSON_VAL_NUMBER, PJ_JSON_VAL_STRING,
  PJ_JSON_VAL_ARRAY, PJ_JSON_VAL_OBJ
}
 

Functions

void pj_json_elem_null (pj_json_elem *el, pj_str_t *name)
 
void pj_json_elem_bool (pj_json_elem *el, pj_str_t *name, pj_bool_t val)
 
void pj_json_elem_number (pj_json_elem *el, pj_str_t *name, float val)
 
void pj_json_elem_string (pj_json_elem *el, pj_str_t *name, pj_str_t *val)
 
void pj_json_elem_array (pj_json_elem *el, pj_str_t *name)
 
void pj_json_elem_obj (pj_json_elem *el, pj_str_t *name)
 
void pj_json_elem_add (pj_json_elem *el, pj_json_elem *child)
 
pj_json_elempj_json_parse (pj_pool_t *pool, char *buffer, unsigned *size, pj_json_err_info *err_info)
 
pj_status_t pj_json_write (const pj_json_elem *elem, char *buffer, unsigned *size)
 
pj_status_t pj_json_writef (const pj_json_elem *elem, pj_json_writer writer, void *user_data)
 

Detailed Description

This API implements JSON file format according to RFC 4627. It can be used to parse, write, and manipulate JSON documents.

Typedef Documentation

typedef pj_status_t(* pj_json_writer)(const char *s, unsigned size, void *user_data)

Type of function callback to write JSON document in pj_json_writef().

Parameters
sThe string to be written to the document.
sizeThe length of the string
user_dataUser data that was specified to pj_json_writef()
Returns
If the callback returns non-PJ_SUCCESS, it will stop the pj_json_writef() function and this error will be returned to caller.

Enumeration Type Documentation

Type of JSON value.

Enumerator
PJ_JSON_VAL_NULL 

Null value (null)

PJ_JSON_VAL_BOOL 

Boolean value (true, false)

PJ_JSON_VAL_NUMBER 

Numeric (float or fixed point)

PJ_JSON_VAL_STRING 

Literal string value.

PJ_JSON_VAL_ARRAY 

Array

PJ_JSON_VAL_OBJ 

Object.

Function Documentation

void pj_json_elem_add ( pj_json_elem el,
pj_json_elem child 
)

Add an element to an object or array.

Parameters
elThe object or array element.
childElement to be added to the object or array.
void pj_json_elem_array ( pj_json_elem el,
pj_str_t name 
)

Initialize element as an empty array

Parameters
elThe element.
nameName to be given to the element, or NULL.
void pj_json_elem_bool ( pj_json_elem el,
pj_str_t name,
pj_bool_t  val 
)

Initialize boolean element with the specified value.

Parameters
elThe element.
nameName to be given to the element, or NULL.
valThe value.
void pj_json_elem_null ( pj_json_elem el,
pj_str_t name 
)

Initialize null element.

Parameters
elThe element.
nameName to be given to the element, or NULL.
void pj_json_elem_number ( pj_json_elem el,
pj_str_t name,
float  val 
)

Initialize number element with the specified value.

Parameters
elThe element.
nameName to be given to the element, or NULL.
valThe value.
void pj_json_elem_obj ( pj_json_elem el,
pj_str_t name 
)

Initialize element as an empty object

Parameters
elThe element.
nameName to be given to the element, or NULL.
void pj_json_elem_string ( pj_json_elem el,
pj_str_t name,
pj_str_t val 
)

Initialize string element with the specified value.

Parameters
elThe element.
nameName to be given to the element, or NULL.
valThe value.
pj_json_elem* pj_json_parse ( pj_pool_t pool,
char *  buffer,
unsigned *  size,
pj_json_err_info err_info 
)

Parse a JSON document in the buffer. The buffer MUST be NULL terminated, or if not then it must have enough size to put the NULL character.

Parameters
poolThe pool to allocate memory for creating elements.
bufferString buffer containing JSON document.
sizeSize of the document.
err_infoOptional structure to be filled with info when parsing failed.
Returns
The root element from the document.
pj_status_t pj_json_write ( const pj_json_elem elem,
char *  buffer,
unsigned *  size 
)

Write the specified element to the string buffer.

Parameters
elemThe element to be written.
bufferOutput buffer.
sizeOn input, it must be set to the size of the buffer. Upon successful return, this will be set to the length of the written string.
Returns
PJ_SUCCESS on success or the appropriate error.
pj_status_t pj_json_writef ( const pj_json_elem elem,
pj_json_writer  writer,
void *  user_data 
)

Incrementally write the element to arbitrary medium using the specified callback to write the document chunks.

Parameters
elemThe element to be written.
writerCallback function which will be called to write text chunks.
user_dataArbitrary user data which will be given back when calling the callback.
Returns
PJ_SUCCESS on success or the appropriate error.

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.