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