/* Callback-based API */
typedef void (*json_walk_callback_t)(void *callback_data, const char *path,
const struct json_token *token);
/*
* Parse `json_string`, invoking `callback` function for each JSON token.
* Return number of bytes processed
*/
int json_walk(const char *json_string, int json_string_length,
json_walk_callback_t callback, void *callback_data);
json_walk() is a low-level, callback based parsing API.
json_walk() calls given callback function for each scanned value.
Callback receives a path to the value, a JSON token that points to the value, and arbitrary user data pointer.
The path is constructed using this rule:
. (dot) is appended to the path[ELEMENT_INDEX] is appendedFor example, consider the following json string:
{ "foo": 123, "bar": [ 1, 2, { "baz": true } ] }.
The sequence of callback invocations will be as follows:
.foo, token: 123.bar[0], token: 1.bar[1], token: 2.bar[2].baz, token: true.bar[2], token: { "baz": true }.bar, token: [ 1, 2, { "baz": true } ]{ "foo": 123, "bar": [ 1, 2, { "baz": true } ] }If top-level element is an array: [1, {"foo": 2}]
[0], token: 1[1].foo, token: 2[1], token: {"foo": 2}[1, {"foo": 2}]If top-level element is an scalar: true
true