lil-json
lil #![no_std] Rust crate to parse & serialize JavaScript Object Notation (JSON). alloc optional. std optional.
only 2 required dependencies + 2 optional dependencies:
- embedded-io for
#![no_std]friendlyWritetrait - numtoa for converting numbers into base 10 ascii
- elsa (optional with
allocfeature enabled) for implementing an infinite length string escape buffer - embedded-io-adapters (optional with
stdfeature enabled) for translatingembedded_io::Writetostd::io::Write
JSON can be serialized into any type that implements embedded_io::Write or a String (with alloc feature enabled). Take a look at the documentation. Note that nested objects and arrays are not currently supported.
Here is a minimal example of printing JSON object to stdout with a one-liner (making use of lil-json::FieldBuffer, core::convert::From for JsonValue, & core::convert::Into for JsonField):
use FieldBuffer;
// output: {"some_number":12345,"some_string":"hello world!","some_boolean":true}
Here is an example of parsing a JSON object
use ;
Here is an example of parsing a JSON object with the alloc feature enabled - no need to pre-allocate space for the fields or escaped strings:
use ;
Check out the examples for more. Still a work in progress. Expect bugs & breaking API changes. Check out the examples to get started.
the following types are currently supported:
- null
- boolean
- strings
- numbers
- objects
- arrays
TODO:
- support null type
- support full unicode strings
- support floating point numbers
- alloc features
- expose serialization methods for terminal types
- support arrays
- support arbitrary crate
- support parsing arbitrary types
- support hex digit escape sequences
- support buffered serialization
- support parsing from stream
- support parsing streaming objects/arrays
- support escaping user-configurable unicode characters
- support embedded-io-async?
- support Cow
- add cool gif to README