APG
… an ABNF Parser Generator
|
The JSON parser API. More...
Go to the source code of this file.
Macros | |
#define | CHARS_LINE_LEN 8 |
Private Object use Only. More... | |
Functions | |
void * | vpJsonCtor (exception *spEx) |
The JSON constructor. More... | |
void | vJsonDtor (void *vpCtx) |
The JSON Parser component destructor. More... | |
abool | bJsonValidate (void *vpCtx) |
Validate a JSON context pointer. More... | |
void * | vpJsonReadFile (void *vpCtx, const char *cpFileName) |
The JSON file reader. More... | |
void * | vpJsonReadArray (void *vpCtx, uint8_t *ucpData, aint uiDataLen) |
The JSON array reader. More... | |
uint8_t * | ucpJsonWrite (void *vpCtx, json_value *spValue, aint *uipCount) |
Converts a sub-tree of values into UTF-8 byte stream of JSON text. More... | |
void | vJsonDisplayInput (void *vpCtx, abool bShowLines) |
Display the input JSON byte stream. More... | |
void | vJsonDisplayValue (void *vpCtx, json_value *spValue, aint uiDepth) |
Display a value and optionally the values in the branch below, if any. More... | |
void * | vpJsonFindKeyA (void *vpCtx, const char *cpKey, json_value *spValue) |
Find JSON values with a specified ASCII key. More... | |
void * | vpJsonFindKeyU (void *vpCtx, const uint32_t *uipKey, aint uiLength, json_value *spValue) |
Find JSON values with the specified 32-bit Unicode key. More... | |
void * | vpJsonTree (void *vpCtx, json_value *spValue) |
Initialize the iterator to walk a value tree. More... | |
void * | vpJsonChildren (void *vpCtx, json_value *spValue) |
Initialize the iterator over the children of the given value as the parent node. More... | |
json_iterator * | spJsonIteratorCtor (json *spJson) |
Private function for internal object use only. Never called by the application. More... | |
void | vJsonIteratorDtor (void *vpIteratorCtx) |
The JSON iterator destructor. More... | |
json_value * | spJsonIteratorFirst (void *vpIteratorCtx) |
Find the first value in the list represented by this iterator. More... | |
json_value * | spJsonIteratorLast (void *vpIteratorCtx) |
Find the last value in the list represented by this iterator. More... | |
json_value * | spJsonIteratorNext (void *vpIteratorCtx) |
Find the next value in the list represented by this iterator. More... | |
json_value * | spJsonIteratorPrev (void *vpIteratorCtx) |
Find the prev value in the list represented by this iterator. More... | |
aint | uiJsonIteratorCount (void *vpIteratorCtx) |
Find the number of values in the list represented by this iterator. More... | |
The JSON parser API.
This JSON parser is meant to be fully compliant with RFC8259. Some of the main features are:
Definition in file json.c.
abool bJsonValidate | ( | void * | vpCtx | ) |
Validate a JSON context pointer.
vpCtx | Pointer to a possibly valid JSON context returned from vpJsonCtor(). |
json_iterator* spJsonIteratorCtor | ( | json * | spJson | ) |
Private function for internal object use only. Never called by the application.
JSON iterators are constructed internally by the JSON object. These functions will return iterators.
json_value* spJsonIteratorFirst | ( | void * | vpIteratorCtx | ) |
Find the first value in the list represented by this iterator.
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
json_value* spJsonIteratorLast | ( | void * | vpIteratorCtx | ) |
Find the last value in the list represented by this iterator.
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
json_value* spJsonIteratorNext | ( | void * | vpIteratorCtx | ) |
Find the next value in the list represented by this iterator.
It should be preceded by a call to spJsonIteratorFirst()
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
json_value* spJsonIteratorPrev | ( | void * | vpIteratorCtx | ) |
Find the prev value in the list represented by this iterator.
It should be preceded by a call to spJsonIteratorNext()
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
uint8_t* ucpJsonWrite | ( | void * | vpCtx, |
json_value * | spValue, | ||
aint * | uipCount | ||
) |
Converts a sub-tree of values into UTF-8 byte stream of JSON text.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
spValue | The root node of the sub-tree to write. spValue can be any value, including the root value, of an existing value tree. |
uipCount | Pointer to an unsigned integer. On completion the number of bytes in the output JSON text is written here. |
aint uiJsonIteratorCount | ( | void * | vpIteratorCtx | ) |
Find the number of values in the list represented by this iterator.
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
void vJsonDisplayInput | ( | void * | vpCtx, |
abool | bShowLines | ||
) |
Display the input JSON byte stream.
This will use a format object to display the JSON input byte stream in a hexdump-style format.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
bShowLines | - if true, the display will show a separate hexdump-type display for each line. |
void vJsonDisplayValue | ( | void * | vpCtx, |
json_value * | spValue, | ||
aint | uiDepth | ||
) |
Display a value and optionally the values in the branch below, if any.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
spValue | - pointer to value to display |
uiDepth | - Indicates the tree depth of the value's sub branch to display. Use zero(0) to display the full sub-tree, one(1) to display just the given value. |
void vJsonDtor | ( | void * | vpCtx | ) |
The JSON Parser component destructor.
Clears the context to prevent accidental use after release and frees all memory allocated by this object. Freed memory includes any and all memory that may have been allocated to iterator or builder objects.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. A NULL pointer is silently ignored. However, a non-NULL pointers must be a valid JSON context pointer. |
void vJsonIteratorDtor | ( | void * | vpIteratorCtx | ) |
The JSON iterator destructor.
Can be called to clean up all memory allocations used by this iterator. However, the JSON destructor vJsonDtor() will free all memory associated with the JSON object, including all iterators and builders.
vpIteratorCtx | A valid context pointer returned from any of the iterator-generating functions. |
NULL is silently ignored. However, if non-NULL must be valid. If invalid the application will silently exit with a BAD_CONTEXT exit code.
void* vpJsonChildren | ( | void * | vpCtx, |
json_value * | spValue | ||
) |
Initialize the iterator over the children of the given value as the parent node.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
spValue | Pointer to the tree value to use at the root node of the walk. |
void* vpJsonCtor | ( | exception * | spEx | ) |
The JSON constructor.
spEx | Pointer to a valid exception structure initialized with XCTOR(). If not valid the application will silently exit with a BAD_CONTEXT exit code. |
void* vpJsonFindKeyA | ( | void * | vpCtx, |
const char * | cpKey, | ||
json_value * | spValue | ||
) |
Find JSON values with a specified ASCII key.
Search for all values with the specified key.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
cpKey | The key as a null-terminated ASCII string. |
spValue | - Pointer to the root node of the sub-tree to search. The given node and all nodes in the sub-tree below, if any, will be searched. |
void* vpJsonFindKeyU | ( | void * | vpCtx, |
const uint32_t * | uipKey, | ||
aint | uiLength, | ||
json_value * | spValue | ||
) |
Find JSON values with the specified 32-bit Unicode key.
Search for all values with the specified key.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
uipKey | Pointer to the array of key string Unicode code points. |
uiLength | The number of code points in the string. |
spValue | Pointer to the root node of the sub-tree to search. The given value and all values in the sub-tree below, if any, will be searched. |
void* vpJsonReadArray | ( | void * | vpCtx, |
uint8_t * | ucpData, | ||
aint | uiDataLen | ||
) |
The JSON array reader.
Reads a an array containing JSON text in UTF-8 format and parses the file into a value tree.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
ucpData | Pointer to the UTF-8 encoded JSON text. |
uiDataLen | The number of bytes of JSON text data. |
void* vpJsonReadFile | ( | void * | vpCtx, |
const char * | cpFileName | ||
) |
The JSON file reader.
Reads a file containing JSON text in UTF-8 format and parses the file into a value tree.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
cpFileName | The name of the file to read. |
void* vpJsonTree | ( | void * | vpCtx, |
json_value * | spValue | ||
) |
Initialize the iterator to walk a value tree.
"Walk" refers to a depth-first traversal of the value tree.
vpCtx | Pointer to a valid parser context previously returned from vpJsonCtor. If invalid the application will silently exit with a BAD_CONTEXT exit code. |
spValue | Pointer to the start value. The given value and all values in the sub-tree below, if any, will be walked. |