jmespath-ruby 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +76 -214
- data/completions/_jmespath +9 -0
- data/completions/jmespath.bash +13 -0
- data/docs/guides/command-line.md +233 -0
- data/docs/guides/compilation.md +2 -1
- data/docs/guides/completion.md +5 -0
- data/lib/jmespath/cli/arguments.rb +5 -8
- data/lib/jmespath/cli/help.rb +115 -33
- data/lib/jmespath/cli/inspection_report.rb +76 -0
- data/lib/jmespath/cli/interactive_commands.rb +58 -0
- data/lib/jmespath/cli/interactive_completion.rb +93 -0
- data/lib/jmespath/cli/interactive_editor.rb +129 -0
- data/lib/jmespath/cli/interactive_editor_state.rb +52 -0
- data/lib/jmespath/cli/interactive_help.rb +36 -0
- data/lib/jmespath/cli/interactive_key_stroke.rb +80 -0
- data/lib/jmespath/cli/interactive_line_editor.rb +11 -0
- data/lib/jmespath/cli/interactive_session.rb +35 -9
- data/lib/jmespath/cli.rb +22 -11
- data/lib/jmespath/version.rb +1 -1
- metadata +24 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b14ceef6fabe47819a391cfeb97e7d30db94a6b8dc3892c5aa9be12995eefaaa
|
|
4
|
+
data.tar.gz: 82d78bc95d24269d31109eeb46e7011e66ee3e58281982d12d5e561454a0eeba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c74c97d25d9002fc1be7fb40e25e5ed930393f31ed5925c9fd60471f6b46333a2764f26eff42416462449c51ad0997ace323b1b4b8f6a7d28c0146907591e958
|
|
7
|
+
data.tar.gz: 9f8e07bf8eab9360043ad8cb342ec17fded6123e7ff03b608ea46b8d01928d8117fd8d97712e58a213bbaed9391a2dfaa78122fe968256a4cc3e6c3f43de4c0d
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) for t
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [1.0.0] - 2026-11-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add topic help for input, output, validation, functions, and interactive sessions, with Bash and Zsh topic completion.
|
|
13
|
+
- Add terminal query editing, cancellation with Ctrl-C, and session history for up to 500 submitted queries through Reline.
|
|
14
|
+
- Complete built-in function names in terminal queries and inspection commands without evaluating input data.
|
|
15
|
+
- Add interactive `:functions` and `:explain QUERY` commands for function discovery and query inspection on stderr.
|
|
16
|
+
- Add interactive `:trace QUERY` with up to 1,000 diagnostic events on stderr and one JSON result on stdout.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Organize the README around common tasks and move detailed CLI rules into a dedicated command-line reference.
|
|
21
|
+
- Keep terminal editing optional at runtime, with plain line input for pipes, redirected stderr, and unsupported terminals.
|
|
22
|
+
- Represent mutually exclusive CLI modes with one internal value while preserving arguments, diagnostics, and exit statuses.
|
|
23
|
+
|
|
8
24
|
## [0.1.3] - 2026-11-02
|
|
9
25
|
|
|
10
26
|
### Added
|
|
@@ -62,7 +78,8 @@ Initial implementation for Ruby 3.3 and later.
|
|
|
62
78
|
The compatibility guide documents intentional corrections and limits.
|
|
63
79
|
Applications that depend on the gem name `jmespath` must change that dependency explicitly.
|
|
64
80
|
|
|
65
|
-
[unreleased]: https://github.com/svyatov/jmespath-ruby/compare/
|
|
81
|
+
[unreleased]: https://github.com/svyatov/jmespath-ruby/compare/v1.0.0...HEAD
|
|
82
|
+
[1.0.0]: https://github.com/svyatov/jmespath-ruby/compare/v0.1.3...v1.0.0
|
|
66
83
|
[0.1.3]: https://github.com/svyatov/jmespath-ruby/compare/v0.1.2...v0.1.3
|
|
67
84
|
[0.1.2]: https://github.com/svyatov/jmespath-ruby/compare/v0.1.1...v0.1.2
|
|
68
85
|
[0.1.1]: https://github.com/svyatov/jmespath-ruby/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
|
@@ -5,14 +5,13 @@ Search JSON and Ruby data with reusable queries and typed custom functions.
|
|
|
5
5
|
- Runs on Ruby 3.3 and later with a pure Ruby implementation.
|
|
6
6
|
- Replaces [jmespath.rb](https://github.com/jmespath/jmespath.rb)'s documented `JMESPath.search` API; see the [migration limits](#replace-jmespathrb).
|
|
7
7
|
- Reuses compiled queries and supports typed custom functions.
|
|
8
|
-
- Measured 7.97x geometric-mean public-search speedup over jmespath 1.6.2 on MRI 4.0.9; see the [benchmark results](docs/guides/comparison.md).
|
|
9
8
|
|
|
10
9
|
## Install
|
|
11
10
|
|
|
12
11
|
In your Ruby project, add the gem with Bundler. Run `bundle init` first if the project has no Gemfile.
|
|
13
12
|
|
|
14
13
|
```sh
|
|
15
|
-
bundle add jmespath-ruby --version "~>
|
|
14
|
+
bundle add jmespath-ruby --version "~> 1.0"
|
|
16
15
|
```
|
|
17
16
|
|
|
18
17
|
Save this Ruby example as `example.rb`:
|
|
@@ -26,48 +25,16 @@ JMESPath.search("user.name", data) #=> "Ada"
|
|
|
26
25
|
|
|
27
26
|
Run it with `bundle exec ruby example.rb`. The final expression returns `"Ada"`.
|
|
28
27
|
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
**Fastest public search in every matching MRI benchmark case.**
|
|
32
|
-
On MRI 4.0.9, jmespath-ruby beats each competing implementation on every workload that both return correctly.
|
|
33
|
-
|
|
34
|
-
| Implementation | Version | Correct workloads | jmespath-ruby public-search speedup |
|
|
35
|
-
| --- | --- | ---: | ---: |
|
|
36
|
-
| **jmespath-ruby** | **0.1.0** | **18/18** | **Baseline** |
|
|
37
|
-
| jmespath (jmespath.rb) | 1.6.2 | 18/18 | **7.97x** |
|
|
38
|
-
| BurtPath | 1.1.2 | 15/18 | **9.99x** |
|
|
39
|
-
| Jamespath | 0.5.1 | 13/18 | **8.07x** |
|
|
40
|
-
|
|
41
|
-
Speedups use geometric means of median times across each competitor's correctly evaluated workloads.
|
|
42
|
-
Measurements use five rounds of 20,000 searches on an Apple M1 Pro.
|
|
43
|
-
The suite includes all 12 upstream benchmark cases and six supplemental cases.
|
|
44
|
-
Results vary by workload: **1.35x to 78.48x faster than jmespath 1.6.2** in this run.
|
|
45
|
-
|
|
46
|
-
Query reuse has different results: BurtPath's private cached runtime is faster in five workloads, and Jamespath has three lower medians.
|
|
47
|
-
The [full comparison](docs/guides/comparison.md) includes those results, JRuby, failures, methodology, and raw samples.
|
|
48
|
-
The JRuby-only `jmespath-jruby` 1.0.0.pre0 fails on the tested JRuby 10.1 runtime; its results are recorded separately.
|
|
49
|
-
|
|
50
|
-
## Why choose jmespath-ruby?
|
|
51
|
-
|
|
52
|
-
- **Reuse work across searches.** Compile once, save query options, and share immutable expressions across threads.
|
|
53
|
-
- **Add functions without global patches.** Typed, immutable registries validate arguments before your callback runs.
|
|
54
|
-
- **Type-check integrations.** The gem ships RBS signatures for its public API.
|
|
55
|
-
- **Use Ruby data directly.** Search string-keyed or symbol-keyed hashes, Structs, arrays, JSON streams, and Pathname inputs.
|
|
56
|
-
- **Control query growth.** The synchronized cache holds at most 32 queries and 1 MiB of source text; expression nesting has an explicit limit.
|
|
57
|
-
|
|
58
|
-
Both Ruby and Python upstream compliance corpora run in the test suite, alongside Ruby-specific input and error checks.
|
|
59
|
-
The [comparison with existing implementations](docs/guides/comparison.md) includes exact versions, rejected workloads, and reproducible measurements.
|
|
60
|
-
|
|
61
|
-
| Feature | jmespath-ruby | jmespath | BurtPath | Jamespath | jmespath-jruby |
|
|
62
|
-
| --- | --- | --- | --- | --- | --- |
|
|
63
|
-
| Public query compilation | Yes | No | No | Yes | Yes |
|
|
64
|
-
| Documented typed function registry | Yes | No | No | No | No |
|
|
65
|
-
| Packaged RBS signatures | Yes | No | No | No | No |
|
|
66
|
-
| Pure Ruby implementation | Yes | Yes | Yes | Yes | No |
|
|
67
|
-
| Ordinary `JMESPath.search` calls | Yes | Yes | Yes | No | No |
|
|
28
|
+
## Common tasks
|
|
68
29
|
|
|
69
|
-
|
|
70
|
-
|
|
30
|
+
| Task | Example | Reference |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| Search Ruby data | [Search](#search) | [Search semantics](docs/guides/search.md) |
|
|
33
|
+
| Reuse a query | [Compile once](#compile-once) | [Compilation](docs/guides/compilation.md) |
|
|
34
|
+
| Require a non-null result | [Required results](#required-results) | [Result rules](docs/guides/compilation.md#required-results) |
|
|
35
|
+
| Handle an evaluation failure | [Failure results](#failure-results) | [Failure ownership](docs/guides/errors.md#failure-results) |
|
|
36
|
+
| Debug an unexpected result | [Trace and inspect](#debug-a-query) | [Tracing](docs/guides/compilation.md#evaluation-tracing) and [inspection](docs/guides/compilation.md#query-inspection) |
|
|
37
|
+
| Search a JSON file from the shell | [Command line](#command-line) | [Command-line reference](docs/guides/command-line.md) |
|
|
71
38
|
|
|
72
39
|
## Replace jmespath.rb
|
|
73
40
|
|
|
@@ -76,7 +43,7 @@ Replace that Gemfile entry:
|
|
|
76
43
|
|
|
77
44
|
```diff
|
|
78
45
|
-gem "jmespath"
|
|
79
|
-
+gem "jmespath-ruby", "~>
|
|
46
|
+
+gem "jmespath-ruby", "~> 1.0"
|
|
80
47
|
```
|
|
81
48
|
|
|
82
49
|
Run `bundle install`. Your Ruby code keeps the same entry points:
|
|
@@ -94,16 +61,6 @@ See [compatibility and deliberate corrections](docs/guides/compatibility.md) bef
|
|
|
94
61
|
|
|
95
62
|
## Search
|
|
96
63
|
|
|
97
|
-
Use `Expression#fetch` when a Ruby caller requires a non-null result:
|
|
98
|
-
|
|
99
|
-
```ruby
|
|
100
|
-
JMESPath.compile("user.name").fetch({user: {name: "Ada"}}) #=> "Ada"
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Null results raise `JMESPath::Errors::NullResultError`, whose `expression` attribute contains the query text.
|
|
104
|
-
False, zero, and empty values succeed.
|
|
105
|
-
See [required query results](docs/guides/compilation.md#required-results) for options and suppression behavior.
|
|
106
|
-
|
|
107
64
|
Use `JMESPath.search` in Ruby code to evaluate a query:
|
|
108
65
|
|
|
109
66
|
```ruby
|
|
@@ -119,6 +76,8 @@ Missing fields return nil.
|
|
|
119
76
|
Projections omit nil results and retain false values.
|
|
120
77
|
The library preserves selected input objects and does not mutate the input.
|
|
121
78
|
|
|
79
|
+
See [search semantics](docs/guides/search.md) for inputs, filters, and projections.
|
|
80
|
+
|
|
122
81
|
## Compile once
|
|
123
82
|
|
|
124
83
|
Use `JMESPath.compile` in Ruby code to reuse a parsed expression:
|
|
@@ -133,6 +92,40 @@ Compiled expressions are immutable and safe to share between threads.
|
|
|
133
92
|
Each search uses separate evaluation state.
|
|
134
93
|
Custom callbacks and input objects remain the caller's responsibility.
|
|
135
94
|
|
|
95
|
+
See [compilation](docs/guides/compilation.md) for saved options, caching, and threading.
|
|
96
|
+
|
|
97
|
+
## Required results
|
|
98
|
+
|
|
99
|
+
Use `Expression#fetch` when a Ruby caller requires a non-null result:
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
JMESPath.compile("user.name").fetch({user: {name: "Ada"}}) #=> "Ada"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Null results raise `JMESPath::Errors::NullResultError`, whose `expression` attribute contains the query text.
|
|
106
|
+
False, zero, and empty values succeed.
|
|
107
|
+
See [required query results](docs/guides/compilation.md#required-results) for options and suppression behavior.
|
|
108
|
+
|
|
109
|
+
## Failure results
|
|
110
|
+
|
|
111
|
+
Use `Expression#try_search` in Ruby code to distinguish a successful null result from a library-owned failure:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
query = JMESPath.compile("length(@)")
|
|
115
|
+
query.try_search("Ada").value #=> 3
|
|
116
|
+
query.try_search(4).success? #=> false
|
|
117
|
+
query.try_search(4).error.function_name #=> "length"
|
|
118
|
+
JMESPath.compile("missing").try_search({}).success? #=> true
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The frozen `JMESPath::SearchResult` exposes `success?`, `value`, and the original `error`.
|
|
122
|
+
Library-owned evaluation, JSON parsing, and native input I/O failures become failure results.
|
|
123
|
+
Invalid options and exceptions from application callbacks or conversions still raise.
|
|
124
|
+
Compilation can raise syntax errors before `try_search` runs.
|
|
125
|
+
See [failure results](docs/guides/errors.md#failure-results) for ownership and suppression rules.
|
|
126
|
+
|
|
127
|
+
## Debug a query
|
|
128
|
+
|
|
136
129
|
In Ruby code, inspect the query without evaluating input or resolving function names:
|
|
137
130
|
|
|
138
131
|
```ruby
|
|
@@ -152,14 +145,24 @@ report[:events].map { |event| event[:type] } #=> ["field_null", "projection_omis
|
|
|
152
145
|
|
|
153
146
|
See [evaluation tracing](docs/guides/compilation.md#evaluation-tracing) for event types, local item indexes, and truncation.
|
|
154
147
|
|
|
155
|
-
|
|
148
|
+
## Command line
|
|
156
149
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
Both `jmespath` and `jmespath.rb` search JSON from a file or stdin:
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
jmespath --file document.json 'user.name'
|
|
161
154
|
```
|
|
162
155
|
|
|
156
|
+
For a document containing `{"user":{"name":"Ada"}}`, stdout contains `"Ada"` and a newline.
|
|
157
|
+
See the [command-line reference](docs/guides/command-line.md) for query files, output modes, validation, and interactive sessions.
|
|
158
|
+
Interactive sessions support query editing, session history, and function completion.
|
|
159
|
+
Start a session with `jmespath --interactive --file document.json`.
|
|
160
|
+
Use `:functions` to list built-in signatures and descriptions.
|
|
161
|
+
Use `:explain QUERY` for structure or `:trace QUERY` for missing-value diagnostics.
|
|
162
|
+
Inspection reports use stderr; query results use stdout as JSON.
|
|
163
|
+
Use [shell completion](docs/guides/completion.md) for Bash and Zsh setup.
|
|
164
|
+
Run `jmespath --help` for common commands or `jmespath --help input` for input rules.
|
|
165
|
+
|
|
163
166
|
## Custom functions
|
|
164
167
|
|
|
165
168
|
Create a function registry in Ruby code and pass it to `JMESPath.search`:
|
|
@@ -187,173 +190,32 @@ See [registry inspection](docs/guides/functions.md#registry-inspection) for all
|
|
|
187
190
|
|
|
188
191
|
## Errors and diagnostics
|
|
189
192
|
|
|
190
|
-
Use `Expression#try_search` in Ruby code to distinguish a successful null result from a library-owned failure:
|
|
191
|
-
|
|
192
|
-
```ruby
|
|
193
|
-
query = JMESPath.compile("length(@)")
|
|
194
|
-
query.try_search("Ada").value #=> 3
|
|
195
|
-
query.try_search(4).success? #=> false
|
|
196
|
-
query.try_search(4).error.function_name #=> "length"
|
|
197
|
-
JMESPath.compile("missing").try_search({}).success? #=> true
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
The frozen `JMESPath::SearchResult` exposes `success?`, `value`, and the original `error`.
|
|
201
|
-
Library-owned evaluation, JSON parsing, and native input I/O failures become failure results.
|
|
202
|
-
Invalid options and exceptions from application callbacks or conversions still raise.
|
|
203
|
-
Compilation can raise syntax errors before `try_search` runs.
|
|
204
|
-
See [failure results](docs/guides/errors.md#failure-results) for ownership and suppression rules.
|
|
205
|
-
|
|
206
193
|
Format syntax failures in Ruby with `JMESPath::Diagnostic.format(error)` to get source coordinates, a query excerpt, and a caret.
|
|
207
194
|
Function type and arity errors expose immutable validation data, including the function name, signature, argument counts or types, and available source ranges.
|
|
208
195
|
Unknown-function errors expose the missing name and up to three suggestions from the active registry.
|
|
209
196
|
See [errors and diagnostics](docs/guides/errors.md) for examples, nullable fields, and source-location limits.
|
|
210
197
|
|
|
211
|
-
##
|
|
212
|
-
|
|
213
|
-
Both `jmespath` and `jmespath.rb` accept an expression and a JSON document from stdin or `--file PATH`.
|
|
214
|
-
Use `--query-file PATH` to read the expression from a UTF-8 file.
|
|
215
|
-
See [shell completion](docs/guides/completion.md) for manual Bash and Zsh setup for both executable names.
|
|
216
|
-
|
|
217
|
-
```sh
|
|
218
|
-
printf '%s\n' '{"user":{"name":"Ada"}}' | jmespath 'user.name'
|
|
219
|
-
jmespath --file document.json 'user.name'
|
|
220
|
-
jmespath 'user.name' --file document.json
|
|
221
|
-
jmespath --file 'my document.json' 'user.name'
|
|
222
|
-
jmespath --file=--document.json 'user.name'
|
|
223
|
-
jmespath --file ./--document.json 'user.name'
|
|
224
|
-
jmespath --file - 'user.name'
|
|
225
|
-
jmespath --file document.json -- 'user.name'
|
|
226
|
-
jmespath --query-file query.jmespath < document.json
|
|
227
|
-
jmespath --query-file query.jmespath --file document.json
|
|
228
|
-
jmespath --pretty 'items' < document.json
|
|
229
|
-
jmespath --raw-output 'user.name' < document.json
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
Document files are read as UTF-8 and closed after parsing, before query evaluation in single-document mode.
|
|
233
|
-
File input leaves stdin unused; omitting `--file` selects stdin.
|
|
234
|
-
Paths are literal: `--file -` reads a file named `-`.
|
|
235
|
-
Quote filenames with spaces; use the equals form or `./` prefix for option-like filenames.
|
|
236
|
-
Options can precede or follow the expression; `--` ends option parsing.
|
|
237
|
-
Supply exactly one query source: a positional expression or `--query-file PATH`.
|
|
238
|
-
Repeated file options, unknown options, missing values, and conflicting or absent query sources are usage failures.
|
|
239
|
-
Help and version flags must appear alone.
|
|
240
|
-
|
|
241
|
-
List built-in functions from the shell without reading stdin:
|
|
242
|
-
|
|
243
|
-
```sh
|
|
244
|
-
jmespath --functions
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
Each line shows a name, accepted argument types, and the description from public function metadata.
|
|
248
|
-
The listing is alphabetical and ends with a notation legend.
|
|
249
|
-
Unions use `|`, homogeneous arrays use `array<T>`, and expression references use `expref`.
|
|
250
|
-
A final `...` means the last argument repeats and remains required.
|
|
251
|
-
Runtime checks can be narrower than the declared types.
|
|
252
|
-
See [the function listing](docs/guides/functions.md#command-line-reference) for examples.
|
|
253
|
-
|
|
254
|
-
Use `--functions` alone; queries, paths, other modes, repeated flags, and values are usage failures.
|
|
255
|
-
The two-argument form `--validate --functions` retains literal query validation.
|
|
256
|
-
Listing exits with status 0 on success, 1 for output failures, or 2 for usage failures.
|
|
257
|
-
Usage failures leave stdout empty and print usage guidance on stderr.
|
|
258
|
-
|
|
259
|
-
Query files retain all source text, including trailing newlines and Unicode diagnostic coordinates.
|
|
260
|
-
An empty query file produces a syntax failure.
|
|
261
|
-
Query files close after reading, before document input is accessed.
|
|
262
|
-
Missing or unreadable query files leave document input untouched.
|
|
263
|
-
In single-document mode, execution parses JSON before compiling the expression.
|
|
264
|
-
Query paths follow the document path rules: `--query-file -` reads a literal file named `-`.
|
|
265
|
-
|
|
266
|
-
The result goes to standard output as compact JSON followed by a newline.
|
|
267
|
-
Use `--pretty` for JSON with two-space indentation and one final newline.
|
|
268
|
-
Both formats support objects, arrays, strings, numbers, booleans, and null, with Unicode preserved.
|
|
269
|
-
Pretty output works with positional or file queries and either document source.
|
|
270
|
-
Repeated `--pretty` options are usage failures.
|
|
271
|
-
Pretty formatting preserves stderr diagnostics, source coordinates, and exit statuses; failures before output starts leave stdout empty.
|
|
272
|
-
Use `--raw-output` to print string results without JSON quotes or escape encoding.
|
|
273
|
-
Other result types retain compact JSON encoding.
|
|
274
|
-
Raw output appends one newline and preserves every embedded and trailing newline in the result.
|
|
275
|
-
An empty string produces one newline; a string ending with one newline produces two.
|
|
276
|
-
Repeated `--raw-output` options and combinations with `--pretty` are usage failures.
|
|
277
|
-
Raw output preserves stderr diagnostics, source coordinates, and exit statuses; failures before output starts leave stdout empty.
|
|
278
|
-
Syntax, function type, and arity failures include source coordinates, a query excerpt, and a caret when available.
|
|
279
|
-
Unknown functions suggest similar registered names.
|
|
280
|
-
Malformed JSON input reports `Invalid JSON input` without including document fragments.
|
|
281
|
-
These failures go to standard error and exit with status 1.
|
|
282
|
-
Usage failures exit with status 2; `--help` and `--version` exit with status 0 without reading input.
|
|
283
|
-
|
|
284
|
-
Process independent JSON records with these shell commands:
|
|
285
|
-
|
|
286
|
-
```sh
|
|
287
|
-
jmespath --json-lines 'user.name' < events.jsonl
|
|
288
|
-
jmespath --json-lines --file events.jsonl --query-file query.jmespath
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
JSON Lines mode compiles the query once before opening document input or reading stdin.
|
|
292
|
-
Each physical line must contain one complete JSON value; blank and whitespace-only lines fail.
|
|
293
|
-
LF, CRLF, and a final record without a newline are accepted.
|
|
294
|
-
Each result is compact JSON followed by a newline, including `null` and `false`.
|
|
295
|
-
Empty input succeeds without output when the query is valid; an invalid query still fails.
|
|
296
|
-
|
|
297
|
-
Processing stops at the first failure with status 1 and an `Input line N:` diagnostic prefix.
|
|
298
|
-
Earlier results remain on stdout; check the exit status before treating output as complete.
|
|
299
|
-
Query compilation and file-open errors have no input line prefix.
|
|
300
|
-
Memory is proportional to the current record, its evaluation, and its serialized result, plus the compiled query.
|
|
301
|
-
Output uses normal buffering.
|
|
302
|
-
Owned files close after processing; caller-owned streams remain open.
|
|
303
|
-
Injected `CLI.run` input needs `gets` for JSON Lines or `read` for document mode; output needs only `puts`.
|
|
304
|
-
Repeated `--json-lines` flags and combinations with `--pretty`, `--raw-output`, or validation are usage failures.
|
|
305
|
-
|
|
306
|
-
Start a session against one loaded document:
|
|
307
|
-
|
|
308
|
-
```sh
|
|
309
|
-
jmespath --interactive --file document.json
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Enter one UTF-8 query per line; empty lines and lines containing only spaces or tabs are ignored.
|
|
313
|
-
Use `:help` for session instructions and `:quit` to finish, or end input with EOF.
|
|
314
|
-
Queries accept LF, CRLF, and a final line without a newline.
|
|
315
|
-
Each successful query prints compact JSON and a final newline to stdout, then flushes when the stream supports it.
|
|
316
|
-
Prompts appear only when stdin is a terminal; prompts, help, and diagnostics use stderr.
|
|
317
|
-
The document loads once and its file closes before the first prompt or command read.
|
|
318
|
-
|
|
319
|
-
Queries can also come from a pipe without prompts:
|
|
320
|
-
|
|
321
|
-
```sh
|
|
322
|
-
printf 'user.name\nlength(user.name)\n' | jmespath --interactive --file document.json
|
|
323
|
-
```
|
|
198
|
+
## Performance
|
|
324
199
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
Interactive mode requires `--file PATH` and rejects positional queries, `--query-file`, other modes, information flags, and repeated flags.
|
|
330
|
-
Readers supplied to `CLI.run` need `gets`; `tty?` is optional and absent detection means no prompts.
|
|
331
|
-
Writers need `puts`; `flush` is optional except for terminal prompts, whose diagnostic stream needs both `print` and `flush`.
|
|
332
|
-
Caller-owned streams remain open; history, completion, multiline editing, and document reloads are unavailable.
|
|
200
|
+
Measured public search is 7.97x faster than jmespath 1.6.2 by geometric mean on MRI 4.0.9 across 18 matching workloads.
|
|
201
|
+
Query reuse has different results across implementations and runtimes.
|
|
202
|
+
See the [full comparison](docs/guides/comparison.md) for exact versions, workload results, and methodology.
|
|
203
|
+
See [performance measurements](docs/guides/performance.md) for cache, startup, and memory experiments.
|
|
333
204
|
|
|
334
|
-
|
|
205
|
+
## Why choose jmespath-ruby?
|
|
335
206
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
207
|
+
- **Reuse work across searches.** Compile once, save query options, and share immutable expressions across threads.
|
|
208
|
+
- **Add functions without global patches.** Typed, immutable registries validate arguments before your callback runs.
|
|
209
|
+
- **Type-check integrations.** The gem ships RBS signatures for its public API.
|
|
210
|
+
- **Use Ruby data directly.** Search string-keyed or symbol-keyed hashes, Structs, arrays, JSON streams, and Pathname inputs.
|
|
211
|
+
- **Control query growth.** The synchronized cache holds at most 32 queries and 1 MiB of source text; expression nesting has an explicit limit.
|
|
341
212
|
|
|
342
|
-
Both
|
|
343
|
-
|
|
344
|
-
Combining `--pretty` with validation is a usage failure, rejected before opening input files or reading stdin.
|
|
345
|
-
Combining `--raw-output` with validation follows the same rule.
|
|
346
|
-
The exact two-argument form `--validate EXPRESSION` always treats the second argument as query text, including flag-like text.
|
|
347
|
-
Thus `jmespath --validate --pretty` validates the literal expression `--pretty`.
|
|
348
|
-
Likewise, `jmespath --validate --raw-output` validates the literal expression `--raw-output`.
|
|
349
|
-
Valid syntax produces no output and exits with status 0.
|
|
350
|
-
Query failures print a diagnostic to standard error and exit with status 1; incorrect usage exits with status 2.
|
|
351
|
-
Validation does not check function availability or runtime argument types.
|
|
352
|
-
The Ruby interface is `JMESPath.validate(expression, max_depth: 128)`.
|
|
353
|
-
See [CLI diagnostics](docs/guides/errors.md#cli-diagnostics) for examples and fallback behavior.
|
|
213
|
+
Both Ruby and Python upstream compliance corpora run in the test suite, alongside Ruby-specific input and error checks.
|
|
214
|
+
The [comparison with existing implementations](docs/guides/comparison.md) includes exact versions, rejected workloads, and reproducible measurements.
|
|
354
215
|
|
|
355
216
|
## Guides
|
|
356
217
|
|
|
218
|
+
- [Command-line reference](docs/guides/command-line.md)
|
|
357
219
|
- [Search semantics](docs/guides/search.md)
|
|
358
220
|
- [Compilation, caching, and threading](docs/guides/compilation.md)
|
|
359
221
|
- [Built-in and custom functions](docs/guides/functions.md)
|
data/completions/_jmespath
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
#compdef jmespath jmespath.rb
|
|
2
2
|
local index expecting_path=0 literal_path=0 value raw option candidate suffix
|
|
3
3
|
local -a paths
|
|
4
|
+
if ((CURRENT > 2)); then
|
|
5
|
+
case ${(Q)words[2]} in
|
|
6
|
+
--help|-h)
|
|
7
|
+
if ((CURRENT == 3)); then
|
|
8
|
+
compadd -- input output validate functions interactive
|
|
9
|
+
fi
|
|
10
|
+
return ;;
|
|
11
|
+
esac
|
|
12
|
+
fi
|
|
4
13
|
for ((index = 2; index < CURRENT; index++)); do
|
|
5
14
|
if ((expecting_path)); then expecting_path=0; continue; fi
|
|
6
15
|
case ${(Q)words[index]} in
|
data/completions/jmespath.bash
CHANGED
|
@@ -103,6 +103,19 @@ _jmespath_completion() {
|
|
|
103
103
|
current=${words[${#words[@]}-1]}
|
|
104
104
|
COMPREPLY=()
|
|
105
105
|
|
|
106
|
+
if ((${#words[@]} > 2)); then
|
|
107
|
+
_jmespath_completion_unquote "${words[1]}"
|
|
108
|
+
case $REPLY in
|
|
109
|
+
--help|-h)
|
|
110
|
+
((${#words[@]} == 3)) || return
|
|
111
|
+
_jmespath_completion_unquote "$current"
|
|
112
|
+
while IFS= read -r candidate; do
|
|
113
|
+
COMPREPLY[${#COMPREPLY[@]}]=$candidate
|
|
114
|
+
done < <(compgen -W 'input output validate functions interactive' -- "$REPLY")
|
|
115
|
+
return ;;
|
|
116
|
+
esac
|
|
117
|
+
fi
|
|
118
|
+
|
|
106
119
|
for ((index = 1; index < ${#words[@]} - 1; index++)); do
|
|
107
120
|
_jmespath_completion_unquote "${words[index]}"
|
|
108
121
|
word=$REPLY
|