jscan-rs
High-performance zero-allocation JSON iterator and validator for Rust.
A faithful port of romshark/jscan/v2 (Go).
What it does
jscan traverses JSON without deserializing it. Instead of building a DOM or mapping to structs, it calls your closure for every value it encounters — giving you the type, key, array index, raw value slice, nesting depth, and JSON Pointer path. Validation happens as a side effect.
This is useful when you need to:
- Extract a few fields from large JSON without parsing the whole thing
- Validate JSON syntax at high speed
- Stream-process JSON values with minimal allocations
- Build custom deserializers
Usage
use ;
let json = br#"{"name":"Alice","scores":[98,76,100]}"#;
scan;
// Output:
// /scores/0 = 98
// /scores/1 = 76
// /scores/2 = 100
Validation only
use valid;
assert!;
assert!;
Scanning multiple concatenated values
use scan_one;
let input = br#"123"hello"null"#;
let = scan_one;
// rest = b#""hello"null"#, err = None
Reusable parser (avoids repeated allocation)
use Parser;
let mut parser = new;
for json_doc in &
Iterator API
Inside the callback, the Iterator provides:
| Method | Returns | Description |
|---|---|---|
value_type() |
ValueType |
Object, Array, String, Number, True, False, Null |
value() |
&[u8] |
Raw value slice (empty for objects/arrays) |
key() |
&[u8] |
Object member key including quotes (empty if not a member) |
pointer() |
String |
RFC 6901 JSON Pointer path |
level() |
usize |
Nesting depth (0 = root) |
array_index() |
isize |
Element index in array, or -1 |
value_index() |
usize |
Byte offset of value start in source |
value_index_end() |
isize |
Byte offset of value end, or -1 for containers |
key_index() |
isize |
Byte offset of key start, or -1 |
key_index_end() |
isize |
Byte offset of key end, or -1 |
write_pointer(&mut buf) |
— | Write pointer to a reusable buffer (avoids alloc) |
License
MIT — same as the original Go library.