Expand description
SIMD byte-scan over raw JSON bytes.
Locates "key": occurrences in a JSON document without first parsing
the document into a tree. memchr (AVX2-internal when available)
jumps byte-by-byte to the next structurally relevant character — a
" outside strings, a " or \\ inside strings — so the scanner
traverses the document at near-memory-bandwidth speed.
§When to use
For $..key (all descendants by name) or $..find(@.key op lit)
shapes over a large JSON document where the caller retained the
raw bytes (see Jetro::from_bytes). Skips the tree walk entirely —
scan cost is bounded by byte length, not node count.
§When not to use
- Document already parsed; raw bytes discarded — fall back to the
tree walker in
eval/mod.rs::collect_desc. - Document is tiny (< a few KB):
serde_jsonper-hit parse cost overtakes the scan win.
§Correctness
The scanner respects JSON string-literal escape rules: an unescaped
" toggles in_string, and a \\ inside a string skips the next
byte. A needle match must begin at a " encountered while
in_string is false — exactly where a JSON object-key literal
can legally appear. Hits inside string values ("comment":"the \"test\" case") are therefore rejected.
Structs§
- NumFold
- Fold numeric values over
spansinto(int_sum, float_sum, is_float, n). Integer spans accumulate intoint_sum; a single float promotes the whole fold tofloat_sum(which tracks the running total as f64). Spans that don’t parse as numbers are skipped. - Value
Span - Span of a single JSON value in
bytes: start offset inclusive, end offset exclusive. Produced byfind_key_value_spans; the caller may compare raw bytes against a literal without allocating aValue.
Enums§
- ScanCmp
- Comparison operator for numeric-range byte scans. Mirrors the subset of
ast::BinOpthat makes sense against a canonical JSON number literal. - Scan
Pred - A single predicate against the value paired with a key inside an
enclosing object. Drives
find_enclosing_objects_mixed.
Functions§
- count_
key_ value_ eq - Extract every value for
keywhose raw bytes equallitafter trimming leading whitespace.litis expected to be pre-serialised JSON (e.g.br#""action""#,b"42"). Bytewise comparison is safe for JSON primitives with canonical serialisation; it is not correct for objects/arrays where key order or whitespace may differ. - extract_
values - Extract every value paired with
keyat any depth. Usesfind_key_positionsto locate each"key":site and then parses the single value that follows via a streamingserde_json::Deserializer(stops at the end of the first value — not the whole document). - extract_
values_ eq - Extract the parsed
Valuefor everykeysite whose raw bytes equallit. Matches by bytewise equality on the span — safe for JSON primitives (strings, numbers, bools, null) which serialise canonically, not for objects/arrays. Non-matching sites are skipped without paying theserde_jsonparse cost. - find_
direct_ field - Extract the span of the direct child named
keyinside an object whose bytes span isobj_bytes[0] == b'{'. Depth-aware: matches only keys at the top level of the object, not keys nested inside arrays or sub-objects. Returned span is relative toobj_bytes. - find_
enclosing_ objects_ cmp - Locate the byte span of every enclosing object whose
keyfield is a JSON number satisfyingop threshold. Powers the fast path for$..find(@.key op num)whereop∈<,<=,>,>=. - find_
enclosing_ objects_ eq - Locate the byte span of every enclosing object whose
keyfield equals the canonical-serialised literallit. Powers the SIMD fast path for$..find(@.key == lit). - find_
enclosing_ objects_ eq_ multi - Like
find_enclosing_objects_eqbut accepts N(key, lit)conjuncts. An object is emitted iff it directly contains every listed key with the matching canonical literal value. Each frame carries a bitmask of which conjuncts have matched so far (max 64 conjuncts). - find_
enclosing_ objects_ mixed - Mixed multi-conjunct scan: each conjunct is
(key, ScanPred)and an enclosing object is emitted iff every conjunct matches on the same{...}frame. Generalisesfind_enclosing_objects_eq_multito allow equality literals and numeric-range comparisons in the same query. Frames carry a bitmask of satisfied conjuncts (max 64). - find_
first_ key_ value_ span - Early-exit variant of
find_key_value_spans— returns the first span paired withkeyencountered in document order, orNoneif the key does not appear. Powers theDescendant(k) + .first()fast path: walks only as far as needed to find one match, rather than scanning the entire byte buffer. - find_
key_ positions - Scan raw JSON
bytesfor every"key":occurrence that starts at a structural position (i.e. not inside a string literal). Returns the byte offset of each matching opening"in document order. - find_
key_ value_ spans - Locate the byte span of every value paired with
key. Skips whitespace between:and the value and then walks the value to its end — strings obey escape rules, containers track nesting depth, scalars run until the next structural terminator. - fold_
direct_ field_ nums - Fold the direct child named
keyof each enclosing object span into a singleNumFold. Combinesfind_direct_field+parse_num_spanwithout materialising any intermediateVal. Spans missing the key or whose value is non-numeric are skipped. - fold_
nums - Fold numeric spans for sum/avg/min/max. Walks each span, parses as number, updates the accumulators. Non-numeric spans are skipped.
- parse_
num_ span - Parse a span of JSON numeric bytes. Returns Some((as_i64, as_f64, is_int))
or None if not a valid number. Canonical JSON numbers only:
-?\d+(\.\d+)?(e±\d+)?.