Small JSON Parser in no_std
This library reads and parses JSON strings.
Its intended use case is to read a JSON payload once.
It does not serialise data.
Sample usage
Simply put this in your Cargo.toml
:
[]
= "0.1"
You can read strings and integers easily:
# use ;
#
You can read arrays like this:
# use ;
#
And, of course, any combination of the above:
# use ;
#
If you are unsure what kind of data you have, you can query the [JSONValueType
].
# use ;
#
Verifying Data
To load some JSON, you need only call
# use JSONValue;
let value = parse;
However, this data is malformed. [JSONValue::parse
] will return an Ok
result, as to determine that the data was corrupt would require scanning through the entire string.
The error would only be reported when you attempted to iterate to the fourth item and parse it as a value.
If you need to know that the data is sound, use [JSONValue::verify
]. Alternatively, you can parse and verify in one step.
# use JSONValue;
let value = parse_and_verify;
Features
- All JSON types
- Strings with escape sequences
- Parse ints (using built in parser)
- Parse floats (using built in parser)
- Iterators over arrays
- Object key lookup
- Iterators over objects
- Verify JSON