1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Jetro is a tool for querying and transforming JSON.
//!
//! # Quick start
//!
//! ```rust
//! use jetro::Jetro;
//! use serde_json::json;
//!
//! let j = Jetro::new(json!({
//! "store": {
//! "books": [
//! {"title": "Dune", "price": 12.99},
//! {"title": "Foundation", "price": 9.99}
//! ]
//! }
//! }));
//!
//! let mut r = j.collect(">/store/books/#len").unwrap();
//! let count: i64 = r.from_index(0).unwrap();
//! assert_eq!(count, 2);
//! ```
extern crate pest_derive;
use Parser;
use Parser as Parse;
// Re-export the two types users need most so they don't have to dig into
// sub-modules for everyday use.
pub use ;
use Value;
// ── Jetro ─────────────────────────────────────────────────────────────────────
/// Primary entry point for evaluating Jetro expressions.
///
/// `Jetro` holds a JSON document and evaluates path expressions against it.
/// Internally it delegates to a **thread-local VM** that is shared across every
/// `Jetro` instance on the same thread, so the compile cache and resolution
/// cache accumulate over the lifetime of the thread — not just one query.
///
/// # Example
///
/// ```rust
/// use jetro::Jetro;
/// use serde_json::json;
///
/// let doc = json!({"user": {"name": "Alice", "age": 30}});
/// let j = Jetro::new(doc);
///
/// let mut r = j.collect(">/user/name").unwrap();
/// let name: String = r.from_index(0).unwrap();
/// assert_eq!(name, "Alice");
///
/// // The same instance can be queried multiple times.
/// let mut r2 = j.collect(">/user/age").unwrap();
/// let age: i64 = r2.from_index(0).unwrap();
/// assert_eq!(age, 30);
/// ```
/// Convenience: create a `Jetro` instance directly from a `serde_json::Value`.
///
/// ```rust
/// use jetro::Jetro;
/// use serde_json::json;
///
/// let mut r = Jetro::from(json!({"x": 42})).collect(">/x").unwrap();
/// let x: i64 = r.from_index(0).unwrap();
/// assert_eq!(x, 42);
/// ```