A Lua JSON parser
- Simple and fast
- Return the errow message to give the position where the JSON data is wrong
- The APIs are similar to CJson
The whole lib depends on the JSON data structure, we don't call it "object" because JSON has a value type is called "object"
The JSON data structure format:
{JSON_TYPE, name, value}
The value inside could be a basic data such as string, number, true, false, null, or a nested JSON data structure. Only the the pair has non-empty "name".
-
parse(buf)
buf: The JSON data buf
The return is the JSON data structure used by other APIs.
-
find(json, name)
Find a JSON data in object
The return is the JSON data structure, check the example_api.lua to find the usage.
-
is_object(json)
Determine if the JSON data is a object
The return is true or false
-
is_array(json)
Same as above
-
is_pair(json)
Same as above
-
is_string(json)
Same as above
-
is_number(json)
Same as above
-
is_true(json)
Same as above
-
is_false(json)
Same as above
-
is_null(json)
Same as above
-
value_of(json)
Get the basic value of a JSON data The return is true or false or nil or string or number, check the example_api.lua
-
walk(json, cb_in, cb_out, uap)
Walk whe whole JSON data, check the example_walk.lua
-
foreach(json, cb, uap)
Transverse the JSON data, check the example_foreach.lua
-
get_pair_name(json)
Get the name of pair, '"test" : 123' pair will retuen "test"
-
get_pair_value(json)
Get the data of pair, '"test" : 123' pair will return 123
-
get_array_size(json)
Get the size of array
-
get_array_item(json, index)
Get the data of array at index, return is the JSON data structure