JSON Utilities. More...

Modules

Types
JSON data types.
 
Macros
JSON macros.
 

Functions

zos_result_t json_parse_context_init (json_parse_context_t **context_ptr, const json_parse_config_t *config)
 Initialize JSON parsing context. More...
 
zos_result_t json_parse_context_deinit (json_parse_context_t *context)
 Cleanup JSON parser context. More...
 
zos_result_t json_parse_chunked (json_parse_context_t *context, void *user)
 Parse JSON formatted data in chunks. More...
 
json_tok_tjson_context_get_token (json_parse_context_t *context, const char *str_val, const json_tok_t *offset_tok)
 Retrieve a token from the JSON context. More...
 
json_tok_tjson_context_get_value (json_parse_context_t *context, const char *str_key, const json_tok_t *offset_tok)
 Return the value token for a specified key. More...
 
json_tok_tjson_context_get_value_with_limit (json_parse_context_t *context, const char *str_key, const json_tok_t *offset_tok, uint32_t limit)
 This does the exact same as json_context_get_value() but limits the number of tokens to search. More...
 
json_tok_tjson_context_skip_tokens (json_parse_context_t *context, const json_tok_t *current_tok, uint16_t count)
 Skip past specified number of tokens in context. More...
 
json_tok_tjson_context_get_current_parent (json_parse_context_t *context)
 Get the current parent Object or Array token. More...
 
void json_encode_buffer (zos_buffer_t *fragment)
 Delimit any JSON special characters in supplied buffer. More...
 
zos_result_t json_decode_buffer (zos_buffer_t *fragment)
 Decoding delimited JSON data to original representation. More...
 

Detailed Description

JSON Utilities.

Function Documentation

json_tok_t* json_context_get_current_parent ( json_parse_context_t context)

Get the current parent Object or Array token.

This returns the current parent Object or Array token.

Parameters
contextPointer to initialized context
Returns
pointer to parent token, NULL else
json_tok_t* json_context_get_token ( json_parse_context_t context,
const char *  str_val,
const json_tok_t offset_tok 
)

Retrieve a token from the JSON context.

After calling json_parse_chunked(), the json_parse_context_t may have one or more tokens. This retrieves a given token from the context.

If the 'str_val' parameter is specified then this finds the first string token with the given value. If the 'offset_tok' parameter is specified then it starts searching from 'offset_tok' token onward. If both parameters are NULL then return the head token. If the token isn't found or there are no tokens in the context then return NULL.

Note
This returns a 'token'. It has no concept of key/value. Refer to json_context_get_value() if the value of a given key is required.
Parameters
contextInitialized JSON context
str_valOptional string value to search for, leave NULL if unused
offset_tokStarting token to begin search, leave NULL if unused
Returns
pointer to found token, NULL else
Examples:
basic/display_stream/display_stream.c, basic/http_server/json_parser_request_processor.c, basic/json_parser/parse_all_examples.c, basic/json_parser/parse_example1.c, and basic/json_parser/parse_example3.c.
json_tok_t* json_context_get_value ( json_parse_context_t context,
const char *  str_key,
const json_tok_t offset_tok 
)

Return the value token for a specified key.

After calling json_parse_chunked(), the json_parse_context_t may have one or more tokens. This returns a corresponding value token for the specified key.

This searches linearly starting at the first token in the context (or 'offset_tok' if supplied) for the first JSON_TYPE_STRING token with its value equal to 'str_key'. It then returns the key token's value (i.e. the token following the found key token).

If the key token is not found or the context is empty then NULL is returned.

Note
'offset_tok' must be either a JSON_TYPE_OBJECT or JSON_TYPE_ARRAY. If it's any other type, the API will automatically begin searching for a JSON_TYPE_OBJECT or JSON_TYPE_ARRAY starting at offset_tok.
Parameters
contextInitialized JSON context
str_keyString key value to search
offset_tokStarting token to begin search, leave NULL if unused
Returns
pointer to value of found key token, NULL else
Examples:
basic/json_parser/parse_example2.c, nxp/nfc3d/cloud_rest.c, and nxp/nfc3d/cloud_websocket.c.
json_tok_t* json_context_get_value_with_limit ( json_parse_context_t context,
const char *  str_key,
const json_tok_t offset_tok,
uint32_t  limit 
)

This does the exact same as json_context_get_value() but limits the number of tokens to search.

json_tok_t* json_context_skip_tokens ( json_parse_context_t context,
const json_tok_t current_tok,
uint16_t  count 
)

Skip past specified number of tokens in context.

After calling json_parse_chunked(), the json_parse_context_t may have one or more tokens. This is a helper API for skipping past a specified number of tokens.

If current_tok is given as an argument, then this will return current_tok + count tokens. If current_tok is NOT given, then this will return the first token in the context + count tokens. If the count token is not available then this returns NULL.

Parameters
contextInitialized JSON context
current_tokOptional token to begin from, begin from first token in context otherwise
countNumber of tokens to skip
Returns
pointer to first token after skipped tokens, NULL if not available
zos_result_t json_decode_buffer ( zos_buffer_t fragment)

Decoding delimited JSON data to original representation.

The decoding is done in-place. The zos_buffer_t will be updated to reflect the new data size.

Parameters
fragmentBuffer contain data to JSON decode
Returns
result of decoding
void json_encode_buffer ( zos_buffer_t fragment)

Delimit any JSON special characters in supplied buffer.

This backslash delimits any special JSON characters in the supplied buffer data in-place. The given buffer must be larger enough to hold the additional backslash characters (if necessary). The size of the zos_buffer_t will be updated to reflect the new data size.

Parameters
fragmentBuffer hold data to JSON encode, buffer must be large enough to hold additional backslash characters
Examples:
demo/accelerometer_stream/accelerometer_stream.c, demo/gps/main.c, demo/moray3d/moray3d.c, nxp/nfc3d/local.c, nxp/nxp3d/nxp3d.c, sensors/accel_interrupt/main.c, and sensors/skink/main.c.
zos_result_t json_parse_chunked ( json_parse_context_t context,
void *  user 
)

Parse JSON formatted data in chunks.

This will parse JSON data and optionally allocate tokens. This may be called multiple times for a given set of JSON data.

Call json_parse_context_init() first to initialize a parsing context.

After parsing call json_context_get_token() to retrieve a token.

Parameters
contextPreviously initialize JSON context
userOptional user data to be passed to json_parse_reader_t and json_token_callback_t
Returns
zos_result_t result of api call
Examples:
basic/display_stream/display_stream.c, basic/http_server/json_parser_request_processor.c, basic/json_parser/parse_all_examples.c, basic/json_parser/parse_example1.c, basic/json_parser/parse_example2.c, basic/json_parser/parse_example3.c, basic/json_parser/parse_example9.c, nxp/nfc3d/cloud_rest.c, and nxp/nfc3d/cloud_websocket.c.
zos_result_t json_parse_context_deinit ( json_parse_context_t context)

Cleanup JSON parser context.

This cleans up the allocated parsing context. This also de-allocates any allocated tokens from parsing.

Parameters
contextJSON parsing context to de-initialize
Returns
zos_result_t result of api call
Examples:
basic/display_stream/display_stream.c, basic/http_server/json_parser_request_processor.c, basic/json_parser/parse_all_examples.c, basic/json_parser/parse_example1.c, basic/json_parser/parse_example2.c, basic/json_parser/parse_example3.c, basic/json_parser/parse_example9.c, nxp/nfc3d/cloud_rest.c, and nxp/nfc3d/cloud_websocket.c.
zos_result_t json_parse_context_init ( json_parse_context_t **  context_ptr,
const json_parse_config_t config 
)

Initialize JSON parsing context.

This allocates a JSON parsing context configured with the given configuration.

Call json_parse_context_deinit() to cleanup this context.

Parameters
context_ptrPointer to hold pointer to allocated context
configContext configuration
Returns
zos_result_t result of api call
Examples:
basic/display_stream/display_stream.c, basic/http_server/json_parser_request_processor.c, basic/json_parser/parse_all_examples.c, basic/json_parser/parse_example1.c, basic/json_parser/parse_example2.c, basic/json_parser/parse_example3.c, basic/json_parser/parse_example9.c, nxp/nfc3d/cloud_rest.c, and nxp/nfc3d/cloud_websocket.c.