Expand description
Read JSON one value at a time: fast, strict, and with every number exact.
A Cursor walks through a JSON document from start to end. You ask for the next key, string
or number, and it hands it to you straight from your bytes, so you can build your own types
with no tree in between.
use json_cursor::Cursor;
let mut cursor = Cursor::new(r#"{"name": "Ada", "born": 1815, "languages": ["English"]}"#);
let mut buf = String::new(); // used only when a key or string has escapes
let mut next = cursor.first_key(&mut buf)?;
while let Some(key) = next {
match key {
"name" => assert_eq!(cursor.string(&mut buf)?, "Ada"),
"born" => assert_eq!(cursor.number()?.as_i64(), Some(1815)),
_ => cursor.skip()?, // anything else is checked, then passed over
}
next = cursor.next_key(&mut buf)?;
}
cursor.finish()?; // only whitespace may followCursorreads a document one value at a time.Numberkeeps a number’s text exactly, and gives its value as ani64or anf64.validatechecks a whole document in one call.Errorsays what went wrong, and at which byte.
The README has a guide, and the benchmarks against other parsers.
Structs§
- Cursor
- A strict JSON pull cursor over text.
- Error
- Why the bytes are not JSON, and the byte where the cursor found out.
- Number
- A number as the cursor read it.
Enums§
- Error
Kind - Why the bytes are not JSON.
- Kind
- What kind of value is next, from its first byte.
- Value
- The next value, as
Cursor::valuereads it.
Constants§
- DEFAULT_
DEPTH_ LIMIT - How deep
Cursor::skipgoes into arrays and objects, unless set withCursor::with_depth_limit: serde_json’s limit.
Functions§
- validate
- Checks that
byteshold one JSON value, with nothing but whitespace around it.