Include this header file to use coreJSON in your application. More...
#include <stddef.h>Go to the source code of this file.
Macros | |
| #define | MAX_INDEX_VALUE ( 0x7FFFFFF7 ) /* 2^31 - 9 */ |
| The largest value usable as an array index in a query for JSON_Search(), ~2 billion. | |
Enumerations | |
| enum | JSONStatus_t { JSONPartial = 0 , JSONSuccess , JSONIllegalDocument , JSONMaxDepthExceeded , JSONNotFound , JSONNullParameter , JSONBadParameter } |
| Return codes from coreJSON library functions. More... | |
Functions | |
| JSONStatus_t | JSON_Validate (const char *buf, size_t max) |
| Parse a buffer to determine if it contains a valid JSON document. More... | |
| JSONStatus_t | JSON_Search (char *buf, size_t max, const char *query, size_t queryLength, char **outValue, size_t *outValueLength) |
Find a key or array index in a JSON document and output the pointer outValue to its value. More... | |
Include this header file to use coreJSON in your application.
| JSONStatus_t JSON_Validate | ( | const char * | buf, |
| size_t | max | ||
| ) |
Parse a buffer to determine if it contains a valid JSON document.
| [in] | buf | The buffer to parse. |
| [in] | max | The size of the buffer. |
Example
See core_json.h for docs.
Verify that the entire buffer contains exactly one scalar or collection within optional whitespace.
| JSONStatus_t JSON_Search | ( | char * | buf, |
| size_t | max, | ||
| const char * | query, | ||
| size_t | queryLength, | ||
| char ** | outValue, | ||
| size_t * | outValueLength | ||
| ) |
Find a key or array index in a JSON document and output the pointer outValue to its value.
Any value may also be an object or an array to a maximum depth. A search may descend through nested objects or arrays when the query contains matching key strings or array indexes joined by a separator.
For example, if the provided buffer contains {"foo":"abc","bar":{"foo":"xyz"}}, then a search for 'foo' would output abc, 'bar' would output {"foo":"xyz"}, and a search for 'bar.foo' would output xyz.
If the provided buffer contains [123,456,{"foo":"abc","bar":[88,99]}], then a search for '[1]' would output 456, '[2].foo' would output abc, and '[2].bar[0]' would output 88.
On success, the pointer outValue points to a location in buf. No null termination is done for the value. For valid JSON it is safe to place a null character at the end of the value, so long as the character replaced is put back before running another search.
| [in] | buf | The buffer to search. |
| [in] | max | size of the buffer. |
| [in] | query | The object keys and array indexes to search for. |
| [in] | queryLength | Length of the key. |
| [out] | outValue | A pointer to receive the address of the value found. |
| [out] | outValueLength | A pointer to receive the length of the value found. |
Example
See core_json.h for docs.