Skip to main content

Crate jetro_core

Crate jetro_core 

Source
Expand description

Jetro core — parser, compiler, and VM for the Jetro JSON query language.

§Execution path

source text
  │  parse::parser::parse() → Expr AST
  │  plan::physical::plan_query() → QueryPlan (physical IR)
  │  exec::router::collect_*() → dispatches to:
  │    StructuralIndex backend  (jetro-experimental bitmap)
  │    ViewPipeline backend     (borrowed tape/Val navigation)
  │    Pipeline backend         (pull-based composed stages)
  └─  VM fallback               (bytecode stack machine)

§Quick start

use jetro_core::Jetro;
let j = Jetro::from_bytes(br#"{"books":[{"price":12}]}"#.to_vec()).unwrap();
assert_eq!(j.collect("$.books.len()").unwrap(), serde_json::json!(1));
use jetro_core::JetroEngine;
use std::io::Cursor;

let engine = JetroEngine::new();
let rows = Cursor::new(br#"{"name":"Ada"}
{"name":"Bob"}
"#);
let names = engine.collect_ndjson(rows, "name").unwrap();
assert_eq!(names, vec![serde_json::json!("Ada"), serde_json::json!("Bob")]);

Match-limited NDJSON helpers evaluate a predicate per row, return the original full row for truthy matches, and stop after the requested number of matches:

use jetro_core::JetroEngine;
use std::io::Cursor;

let engine = JetroEngine::new();
let rows = Cursor::new(br#"{"id":1,"active":true}
{"id":2,"active":false}
{"id":3,"active":true}
"#);
let first_two = engine.collect_ndjson_matches(rows, "active", 2).unwrap();
assert_eq!(first_two, vec![
    serde_json::json!({"id": 1, "active": true}),
    serde_json::json!({"id": 3, "active": true}),
]);

Modules§

io
Streaming input/output adapters for query execution.

Macros§

for_each_builtin
Expands $macro!(...) once per BuiltinMethod variant — the single source of truth for “all builtin methods” used by name lookup, registry exports, and any future cross-cutting per-method generation. Variant names match the corresponding defs::* struct names.

Structs§

EvalError
Evaluation error carrying a human-readable message. Propagated through Result<Val, EvalError> across all execution layers.
Jetro
Primary entry point. Holds a JSON document and evaluates expressions against it. Lazy fields (root_val, tape, structural_index, objvec_cache) are populated on first use so callers only pay for the representations a particular query actually needs.
JetroEngine
Long-lived multi-document query engine with an explicit plan cache. Use when the same process evaluates many expressions over many documents — parse/lower/compile work is amortised by this object, not hidden in thread-local state.

Enums§

JetroEngineError
Error returned by JetroEngine::collect_bytes and similar methods that may fail during JSON parsing or during expression evaluation.