lifegraph-json
Zero-dependency JSON crate in Rust with owned, borrowed, tape, and compiled-schema paths.
Why
lifegraph-json is aimed at workloads where generic JSON trees leave performance on the table:
- fast parse-and-inspect flows
- low-allocation parsing
- repeated lookup on wide objects
- repeated serialization of known object shapes
It uses 0 runtime dependencies.
Compatibility surface
lifegraph-json now includes a growing compatibility-oriented API modeled after common serde_json usage:
Value,Number,Mapfrom_str,from_slice,from_readerto_string,to_vec,to_writerjson!value["field"]andvalue[index]- generic
get,get_mut, plusget_index,get_index_mut as_str,as_bool,as_i64,as_u64,as_f64is_null,is_array,is_object,len,is_empty,sort_all_objects
It is not fully drop-in compatible with serde_json yet, but simple code ports are getting much easier.
Newer compatibility helpers now include JSON Pointer access (Value::pointer, Value::pointer_mut), Value::take, pretty-print output helpers, number/null parity helpers, and nested mutable indexing like value["a"]["b"] = ....
Migration sketch
// before
// use serde_json::{json, Value};
// after
use ;
let value: Value = from_str?;
assert_eq!;
assert_eq!;
let built = json!;
let encoded = to_string?;
# Ok::
Example: reader/writer helpers
use ;
use Cursor;
let value = from_reader?;
let mut out = Vecnew;
to_writer?;
# Ok::
Example: tape parsing with compiled lookup keys
use ;
let input = r#"{"name":"hello","flag":true}"#;
let tape = parse_json_tape?;
let root = tape.root.unwrap;
let index = root.build_object_index.unwrap;
let indexed = root.with_index;
let keys = new;
let kinds = indexed
.get_compiled_many
.map
.;
assert_eq!;
# Ok::
Performance direction
On local release-mode comparisons against serde_json, the strongest wins so far have been in specialized paths such as:
- tape parsing on medium/report-like payloads
- deep structural parses
- wide-object repeated lookup with indexed compiled keys
Best observed outliers so far include roughly:
- up to ~6x faster on deep structural parses
- ~4x faster on several tape parse / parse+lookup workloads
- ~3x faster on indexed repeated lookup over wide objects
This crate is best viewed as a performance-oriented JSON toolkit for specific workloads, with a growing compatibility layer for easier adoption.
More drop-in behavior
Common serde_json-style assertions now work too:
# use json;
let value = json!;
assert_eq!;
assert_eq!;
assert_eq!;
json! macro parity
The macro is now much closer to serde_json in practice, including expression-key object entries:
# use json;
let code = 200;
let features = vec!;
let value = json!;
assert_eq!;