jmespath-ruby 0.1.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 +7 -0
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +57 -0
- data/LICENSE +21 -0
- data/LICENSES/python-MIT.txt +21 -0
- data/LICENSES/ruby-Apache-2.0.txt +174 -0
- data/README.md +122 -0
- data/SECURITY.md +16 -0
- data/VERSIONING.md +12 -0
- data/docs/guides/compatibility.md +84 -0
- data/docs/guides/compilation.md +63 -0
- data/docs/guides/errors.md +30 -0
- data/docs/guides/functions.md +65 -0
- data/docs/guides/performance.md +237 -0
- data/docs/guides/search.md +56 -0
- data/exe/jmespath +5 -0
- data/exe/jmespath.rb +5 -0
- data/lib/jmespath/ast.rb +43 -0
- data/lib/jmespath/cache.rb +53 -0
- data/lib/jmespath/cli.rb +36 -0
- data/lib/jmespath/data_access.rb +66 -0
- data/lib/jmespath/errors.rb +53 -0
- data/lib/jmespath/evaluation/construction.rb +20 -0
- data/lib/jmespath/evaluation/logic.rb +42 -0
- data/lib/jmespath/evaluation/projections.rb +43 -0
- data/lib/jmespath/evaluation/scalars.rb +49 -0
- data/lib/jmespath/evaluation/slices.rb +50 -0
- data/lib/jmespath/evaluator.rb +37 -0
- data/lib/jmespath/expression.rb +63 -0
- data/lib/jmespath/expression_reference.rb +15 -0
- data/lib/jmespath/functions/coercions.rb +41 -0
- data/lib/jmespath/functions/collections.rb +84 -0
- data/lib/jmespath/functions/conversion.rb +32 -0
- data/lib/jmespath/functions/function_call.rb +32 -0
- data/lib/jmespath/functions/references.rb +62 -0
- data/lib/jmespath/functions/scalar.rb +74 -0
- data/lib/jmespath/functions/signature.rb +77 -0
- data/lib/jmespath/functions.rb +73 -0
- data/lib/jmespath/input.rb +19 -0
- data/lib/jmespath/lexer.rb +132 -0
- data/lib/jmespath/normalizer.rb +53 -0
- data/lib/jmespath/options.rb +67 -0
- data/lib/jmespath/parser/expressions.rb +70 -0
- data/lib/jmespath/parser/projections.rb +91 -0
- data/lib/jmespath/parser.rb +119 -0
- data/lib/jmespath/plan.rb +153 -0
- data/lib/jmespath/token.rb +6 -0
- data/lib/jmespath/types.rb +84 -0
- data/lib/jmespath/version.rb +7 -0
- data/lib/jmespath.rb +100 -0
- data/sig/jmespath.rbs +55 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cf530e6a526f4e83cc7fd29f7f527fedf0b28add8d0e57b362db7ac96b379cb7
|
|
4
|
+
data.tar.gz: 29b4682722f6371663cd0c84f29119db2c1fd89943ad60db395aead75adc2456
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 40f6a36ceb35cb72fe6dd62651f51ae41a8b79f204f71b6941c754f93ac5a2dd18e08ef9f2ee98791073bae4493b636ebd79ef8196541cccd3b92853310faa22
|
|
7
|
+
data.tar.gz: 8a4e7dfa8ea63e0e6c5e073f7e893a34d76de3267a6300ba5e60cd27d51cc9566be26985dd7e56b51bf31b7b5160bd2e41e634c9f8358483e358631a43357424
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - 2026-11-01
|
|
4
|
+
|
|
5
|
+
Initial implementation for Ruby 3.3 and later.
|
|
6
|
+
|
|
7
|
+
- Implement the JMESPath language and all 26 standard functions.
|
|
8
|
+
- Preserve the public `require "jmespath"` and `JMESPath.search` entry points under the `jmespath-ruby` package name.
|
|
9
|
+
- Add immutable compiled expressions, bounded synchronized caching, and immutable custom function registries.
|
|
10
|
+
- Save custom function registries and error-handling defaults in compiled expressions; expose `Expression#call` as an alias for `search`.
|
|
11
|
+
- Compile common evaluation operations and reduce repeated allocation, field lookup, and function-validation costs.
|
|
12
|
+
- Support Ruby hashes, symbol keys, Struct values, explicit conversion protocols, streams, and paths.
|
|
13
|
+
- Include both command-line executable names, public RBS signatures, and executable YARD examples.
|
|
14
|
+
- Validate pinned Python and Ruby compliance fixtures, declared compatibility corrections, and production-only gem installation.
|
|
15
|
+
- Include reproducible speed and process-memory comparisons across MRI 3.3, 3.4, and 4.0 with default GC settings.
|
|
16
|
+
|
|
17
|
+
The compatibility guide documents intentional corrections and limits.
|
|
18
|
+
Applications that depend on the gem name `jmespath` must change that dependency explicitly.
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Development
|
|
2
|
+
|
|
3
|
+
Use Ruby 3.3 or later.
|
|
4
|
+
Install the locked development bundle with `bundle install`.
|
|
5
|
+
|
|
6
|
+
## Checks
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bundle exec rake
|
|
10
|
+
bundle exec rake docs
|
|
11
|
+
bundle exec rake audit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The default task runs RuboCop, RBS validation, Steep, RSpec, fresh coverage, CRAP analysis, and documentation checks.
|
|
15
|
+
Coverage requires 100% lines and branches.
|
|
16
|
+
Every measurable library method must score at most 10 in coverage-aware CRAP analysis.
|
|
17
|
+
A missing coverage report fails the check.
|
|
18
|
+
Unmeasurable methods are reported for review.
|
|
19
|
+
|
|
20
|
+
Run `bundle exec rspec spec/unit/parser_spec.rb` for a focused test cycle.
|
|
21
|
+
Focused RSpec runs collect coverage without enforcing full-suite thresholds.
|
|
22
|
+
Keep expected values independent of implementation code.
|
|
23
|
+
Add a failing regression test before fixing behavior.
|
|
24
|
+
|
|
25
|
+
## Compatibility fixtures
|
|
26
|
+
|
|
27
|
+
Imported fixtures live under `spec/fixtures/upstream`.
|
|
28
|
+
Their manifest records source commits, paths, licenses, and SHA-256 hashes.
|
|
29
|
+
Preserve imported bytes.
|
|
30
|
+
Place local regression cases and supplemental benchmark expectations outside the imported files.
|
|
31
|
+
|
|
32
|
+
Use `script/differential.rb` with explicit pinned reference checkouts for comparisons.
|
|
33
|
+
Normal tests require neither network access nor Python.
|
|
34
|
+
|
|
35
|
+
## Documentation and releases
|
|
36
|
+
|
|
37
|
+
Write YARD types and executable examples for public APIs.
|
|
38
|
+
Examples ending in `#=>` or `# raises ErrorClass` run through documentation checks.
|
|
39
|
+
Keep private implementation surfaces marked with `@api private`.
|
|
40
|
+
|
|
41
|
+
Use Conventional Commits and focused commits.
|
|
42
|
+
Build and validate an isolated gem before a release.
|
|
43
|
+
Publishing and remote repository operations require separate authorization.
|
|
44
|
+
|
|
45
|
+
## Release
|
|
46
|
+
|
|
47
|
+
Update `lib/jmespath/version.rb` and `CHANGELOG.md` together.
|
|
48
|
+
Run `bundle exec rake release:check` before creating a release tag.
|
|
49
|
+
Push a `vVERSION` tag that exactly matches `JMESPath::VERSION`.
|
|
50
|
+
The release workflow runs the full quality matrix, verifies the tag, archives the built gem, and publishes through RubyGems trusted publishing.
|
|
51
|
+
|
|
52
|
+
The trusted publisher is restricted to `svyatov/jmespath-ruby`, workflow `release.yml`, and GitHub environment `release`.
|
|
53
|
+
The environment accepts release tags matching `v*`.
|
|
54
|
+
The token exchange declares the account's immutable RubyGems owner ID, `71752`, which is required for the first publication.
|
|
55
|
+
No long-lived RubyGems API key is required.
|
|
56
|
+
After publication, create the GitHub release from the archived gem and its matching changelog entry.
|
|
57
|
+
If only GitHub release creation fails, reuse that artifact; do not republish the gem.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leonid Svyatov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
data/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# jmespath-ruby
|
|
2
|
+
|
|
3
|
+
A pure Ruby implementation of JMESPath for Ruby 3.3 and later.
|
|
4
|
+
|
|
5
|
+
Search JSON-compatible values, compile expressions for reuse, and register typed custom functions.
|
|
6
|
+
The package keeps `require "jmespath"` and `JMESPath.search` while using the gem name `jmespath-ruby`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Add the gem to your Gemfile:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem "jmespath-ruby", "~> 0.1.0"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or install it directly:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
gem install jmespath-ruby
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Install from this checkout
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
bundle install
|
|
26
|
+
bundle exec rake build
|
|
27
|
+
gem install ./pkg/jmespath-ruby-0.1.0.gem
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For a local Bundler application:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem "jmespath-ruby", path: "/path/to/jmespath-ruby"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use one provider per bundle.
|
|
37
|
+
A dependency on the package named `jmespath` needs its own dependency change; this gem cannot satisfy that name automatically.
|
|
38
|
+
|
|
39
|
+
## Search
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require "jmespath"
|
|
43
|
+
|
|
44
|
+
data = {people: [{name: "Ada", active: true}, {name: "Lin", active: false}]}
|
|
45
|
+
JMESPath.search("people[?active].name", data) #=> ["Ada"]
|
|
46
|
+
JMESPath.search("people[*].name", data) #=> ["Ada", "Lin"]
|
|
47
|
+
JMESPath.search("missing", data) #=> nil
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Missing fields return nil.
|
|
51
|
+
Projections omit nil results and retain false values.
|
|
52
|
+
The library preserves selected input objects and does not mutate the input.
|
|
53
|
+
|
|
54
|
+
## Compile once
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
expression = JMESPath.compile("user.name")
|
|
58
|
+
expression.search({user: {name: "Ada"}}) #=> "Ada"
|
|
59
|
+
expression.search({user: {name: "Lin"}}) #=> "Lin"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Compiled expressions are immutable and safe to share between threads.
|
|
63
|
+
Each search uses separate evaluation state.
|
|
64
|
+
Custom callbacks and input objects remain the caller's responsibility.
|
|
65
|
+
|
|
66
|
+
Save evaluation options when compiling a query, then use `search` or its `call` alias:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
query = JMESPath.compile("length(name)", disable_visit_errors: true)
|
|
70
|
+
query.call({name: "Ada"}) #=> 3
|
|
71
|
+
query.call({name: nil}) #=> nil
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Custom functions
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
functions = JMESPath::Functions.default.with("double", signature: [[:number]]) { |number| number * 2 }
|
|
78
|
+
JMESPath.search("double(price)", {price: 12}, functions: functions) #=> 24
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Registration returns a separate immutable registry.
|
|
82
|
+
An existing function requires `override: true` to replace it.
|
|
83
|
+
Every argument, including variadic arguments, is validated before the callback runs.
|
|
84
|
+
|
|
85
|
+
## Command line
|
|
86
|
+
|
|
87
|
+
Both `jmespath` and `jmespath.rb` accept an expression and a JSON document on standard input.
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
printf '%s\n' '{"user":{"name":"Ada"}}' | jmespath 'user.name'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The result goes to standard output as JSON.
|
|
94
|
+
Errors go to standard error with a nonzero status.
|
|
95
|
+
|
|
96
|
+
## Guides
|
|
97
|
+
|
|
98
|
+
- [Search semantics](docs/guides/search.md)
|
|
99
|
+
- [Compilation, caching, and threading](docs/guides/compilation.md)
|
|
100
|
+
- [Built-in and custom functions](docs/guides/functions.md)
|
|
101
|
+
- [Errors and limits](docs/guides/errors.md)
|
|
102
|
+
- [Compatibility and migration](docs/guides/compatibility.md)
|
|
103
|
+
- [Performance measurements](docs/guides/performance.md)
|
|
104
|
+
- [Development](CONTRIBUTING.md)
|
|
105
|
+
|
|
106
|
+
## Verify and document
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
bundle exec rake
|
|
110
|
+
bundle exec rake docs
|
|
111
|
+
bundle exec rake audit
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The default task checks tests, fresh coverage, RuboCop, RBS, Steep, coverage-aware CRAP scores, and documentation.
|
|
115
|
+
The gates require 100% line and branch coverage, and a CRAP score at most 10 per measurable library method.
|
|
116
|
+
The audit task separately refreshes the dependency advisory database.
|
|
117
|
+
YARD output is written to `doc/index.html`.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](LICENSE) for authored code.
|
|
122
|
+
Imported compliance fixtures retain their [upstream licenses](LICENSES/).
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
Search evaluates JMESPath syntax without executing Ruby query text.
|
|
4
|
+
Input adapters and custom functions execute caller-supplied Ruby code.
|
|
5
|
+
They are trusted application extensions, not a sandbox boundary.
|
|
6
|
+
|
|
7
|
+
Use finite JSON numbers and avoid cyclic input when comparing or serializing entire values.
|
|
8
|
+
Set a smaller `max_depth` for applications that need a lower nesting limit.
|
|
9
|
+
Bound request sizes and runtime resources at the application boundary.
|
|
10
|
+
|
|
11
|
+
Run `bundle exec rake audit` to refresh the dependency advisory database and check the lockfile.
|
|
12
|
+
A failed database update fails the audit.
|
|
13
|
+
|
|
14
|
+
Report security concerns through a private maintainer contact channel.
|
|
15
|
+
Do not post credentials or private application data in public reports.
|
|
16
|
+
Private repository reporting must be configured before publication.
|
data/VERSIONING.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Versioning
|
|
2
|
+
|
|
3
|
+
The initial package version is 0.1.0.
|
|
4
|
+
The public contract includes the documented Ruby API, language behavior, error categories, options, CLI, and minimum Ruby version.
|
|
5
|
+
Private implementation classes are outside that contract.
|
|
6
|
+
|
|
7
|
+
Before 1.0, a breaking public change requires a minor version.
|
|
8
|
+
After 1.0, a breaking public change requires a major version.
|
|
9
|
+
Dropping Ruby 3.3 support after 1.0 requires a major release.
|
|
10
|
+
|
|
11
|
+
Document corrected reference defects and migration consequences in the changelog.
|
|
12
|
+
A tag or successful build alone does not establish publication.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Compatibility
|
|
2
|
+
|
|
3
|
+
The package is named `jmespath-ruby`. It provides `require "jmespath"` and `JMESPath.search`.
|
|
4
|
+
Select one JMESPath provider in an application bundle.
|
|
5
|
+
|
|
6
|
+
A dependency on the package named `jmespath` does not resolve to `jmespath-ruby` automatically.
|
|
7
|
+
Dependencies that declare that name need their own dependency change before replacing the provider.
|
|
8
|
+
Loading both providers in one process is unsupported because their require paths and constants overlap.
|
|
9
|
+
|
|
10
|
+
## Ruby inputs
|
|
11
|
+
|
|
12
|
+
Search accepts hashes with string or symbol keys, arrays, JSON scalars, Structs, Pathname, IO, and StringIO.
|
|
13
|
+
Objects implementing `to_hash`, `to_ary`, or `to_str` use explicit conversion boundaries.
|
|
14
|
+
A malformed conversion raises TypeError; exceptions from application conversion methods propagate.
|
|
15
|
+
|
|
16
|
+
String keys with non-nil values take precedence over matching symbol keys.
|
|
17
|
+
A nil string-key value allows lookup of an existing symbol key.
|
|
18
|
+
Queries never create symbols or invoke arbitrary Struct methods.
|
|
19
|
+
Selected values preserve their Ruby object identity.
|
|
20
|
+
Constructed arrays, hashes, and literal values belong to each search result.
|
|
21
|
+
|
|
22
|
+
Stream input starts at the current position and remains open after the search.
|
|
23
|
+
Pathname input is opened and closed by the library.
|
|
24
|
+
Invalid JSON retains the JSON parser's error class.
|
|
25
|
+
|
|
26
|
+
## Options and errors
|
|
27
|
+
|
|
28
|
+
The third positional argument remains an options hash; keyword options are also accepted.
|
|
29
|
+
Conflicting duplicate options and unknown option names raise ArgumentError.
|
|
30
|
+
Supported options are `cache_expressions`, `disable_visit_errors`, `functions`, and `max_depth`.
|
|
31
|
+
|
|
32
|
+
The named error classes remain under `JMESPath::Errors`.
|
|
33
|
+
Function validation errors can use subclasses of InvalidTypeError and InvalidArityError.
|
|
34
|
+
Error message wording and private parser objects are outside the compatibility contract.
|
|
35
|
+
Function names resolve during evaluation so compiled expressions can use different custom registries.
|
|
36
|
+
|
|
37
|
+
With `disable_visit_errors: true`, library argument-type and arity failures return nil.
|
|
38
|
+
Syntax, invalid-value, unknown-function, conversion, and application callback failures still raise.
|
|
39
|
+
A callback's exception object and backtrace remain intact.
|
|
40
|
+
|
|
41
|
+
## Deliberate corrections
|
|
42
|
+
|
|
43
|
+
| Behavior | Result |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| Surplus arguments to `reverse` | InvalidArityError |
|
|
46
|
+
| Missing or surplus arguments to `to_array` | InvalidArityError |
|
|
47
|
+
| `min_by` or `max_by` on an empty array | nil |
|
|
48
|
+
| Invalid trailing variadic arguments | InvalidTypeError |
|
|
49
|
+
| Indexes beyond native machine integer range | nil, without a Ruby RangeError |
|
|
50
|
+
|
|
51
|
+
Legacy bare backtick literals and ordering between strings remain supported.
|
|
52
|
+
Numeric operations accept finite integers and floats; non-finite values are outside the JSON number domain.
|
|
53
|
+
Cyclic values raise InvalidValueError when structural comparison or serialization encounters the cycle.
|
|
54
|
+
|
|
55
|
+
## Limits
|
|
56
|
+
|
|
57
|
+
Expression nesting defaults to 128 and can be reduced with `max_depth`.
|
|
58
|
+
The maximum supported setting is 128.
|
|
59
|
+
Nested arrays and objects in JSON literals count toward this limit.
|
|
60
|
+
Compiled searches also check literal depth when a caller requests a lower limit.
|
|
61
|
+
Flat field chains use iterative evaluation and do not consume that nesting budget per field.
|
|
62
|
+
The compilation cache holds at most 32 entries and 1,048,576 source bytes.
|
|
63
|
+
Oversized expressions bypass caching without becoming invalid.
|
|
64
|
+
|
|
65
|
+
## Verification
|
|
66
|
+
|
|
67
|
+
Pinned fixture sources are recorded with SHA-256 hashes in `spec/fixtures/upstream/sources.json`.
|
|
68
|
+
Python reference: `2812594e69d43098ef60f81f4efc404c071b0418`.
|
|
69
|
+
Ruby reference: `5e86ea7da2e954cc12f5b3a8383a43c0a65acba7`.
|
|
70
|
+
|
|
71
|
+
Both compliance corpora run with plain inputs and supported Ruby wrappers.
|
|
72
|
+
Error cases also run with visit-error suppression enabled.
|
|
73
|
+
Benchmark-only cases use separate expectations where the upstream file omits a result.
|
|
74
|
+
Imported fixture bytes remain unchanged.
|
|
75
|
+
|
|
76
|
+
Differential verification checked 1,192 distinct and generated cases against both references.
|
|
77
|
+
There were no unexpected differences.
|
|
78
|
+
The two accepted differences were Ruby's empty-array errors for `min_by` and `max_by`.
|
|
79
|
+
|
|
80
|
+
To repeat the comparison with the pinned library checkouts:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
bundle exec ruby script/differential.rb --python-root /path/to/python --ruby-root /path/to/ruby
|
|
84
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Compilation and concurrency
|
|
2
|
+
|
|
3
|
+
`JMESPath.compile` parses an expression into an immutable `JMESPath::Expression`.
|
|
4
|
+
Each call to `Expression#search` reuses that syntax with separate evaluation state.
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
expression = JMESPath.compile("items[*].name")
|
|
8
|
+
expression.search({items: [{name: "Ada"}]}) #=> ["Ada"]
|
|
9
|
+
expression.search({items: [{name: "Lin"}]}) #=> ["Lin"]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The expression owns a frozen copy of the query text.
|
|
13
|
+
Changing the caller's original string does not change the compiled expression.
|
|
14
|
+
Mutable literal results are copied for each evaluation.
|
|
15
|
+
|
|
16
|
+
## Saved options
|
|
17
|
+
|
|
18
|
+
Pass `functions:` and `disable_visit_errors:` to `compile` to save defaults for repeated searches.
|
|
19
|
+
Configuration is validated once, and compiled operations use the selected registry.
|
|
20
|
+
The `call` method is an alias for `search`.
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
functions = JMESPath::Functions.default.with("double", signature: [[:number]]) { |value| value * 2 }
|
|
24
|
+
query = JMESPath.compile("double(price)", functions: functions, disable_visit_errors: true)
|
|
25
|
+
query.call({price: 12}) #=> 24
|
|
26
|
+
query.search({price: nil}) #=> nil
|
|
27
|
+
query.search({price: 7}, disable_visit_errors: false) #=> 14
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Per-call options override the saved values for that call only.
|
|
31
|
+
Omitted options retain their saved values.
|
|
32
|
+
Conflicting positional and keyword options raise `ArgumentError`.
|
|
33
|
+
Custom registries and configured expressions never enter the shared syntax cache.
|
|
34
|
+
Unknown function names still raise during evaluation, after their arguments are evaluated.
|
|
35
|
+
|
|
36
|
+
## Cache behavior
|
|
37
|
+
|
|
38
|
+
Convenience searches use a synchronized least-recently-used compilation cache.
|
|
39
|
+
The cache retains at most 32 expressions and 1,048,576 source bytes.
|
|
40
|
+
Oversized expressions are parsed without entering the cache.
|
|
41
|
+
Failed parses, input documents, search results, and custom registries are never cached.
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
JMESPath.search("x", {x: 1}, cache_expressions: false) #=> 1
|
|
45
|
+
JMESPath.compile("x", cache_expressions: false).search({x: 2}) #=> 2
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Disabling caching changes parsing cost, not query semantics.
|
|
49
|
+
The same option is accepted by a compiled expression; it already owns parsed syntax.
|
|
50
|
+
|
|
51
|
+
## Threads and callbacks
|
|
52
|
+
|
|
53
|
+
Compiled expressions and immutable function registries can be shared between threads.
|
|
54
|
+
Callers must synchronize changes to input objects and state captured by custom callbacks.
|
|
55
|
+
Returned input objects remain caller-owned and mutable.
|
|
56
|
+
The library does not provide callback timeouts or a security sandbox.
|
|
57
|
+
|
|
58
|
+
## Nesting
|
|
59
|
+
|
|
60
|
+
The default and maximum supported nesting limit is 128.
|
|
61
|
+
Use `max_depth` to select a smaller positive limit when compiling or searching.
|
|
62
|
+
A compiled expression validates a requested search limit without reparsing.
|
|
63
|
+
Flat field chains and pipes use iterative evaluation.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Errors and diagnostics
|
|
2
|
+
|
|
3
|
+
The common base class is `JMESPath::Errors::Error`.
|
|
4
|
+
SyntaxError derives from that base; evaluation errors derive from RuntimeError.
|
|
5
|
+
|
|
6
|
+
| Error | Meaning |
|
|
7
|
+
| --- | --- |
|
|
8
|
+
| `SyntaxError` | Invalid expression syntax, encoding, or nesting |
|
|
9
|
+
| `InvalidTypeError` | Unsupported argument or expression-key type |
|
|
10
|
+
| `InvalidArityError` | Incorrect number of function arguments |
|
|
11
|
+
| `InvalidValueError` | Invalid slice step or cyclic value during structural processing |
|
|
12
|
+
| `UnknownFunctionError` | Function absent from the supplied registry |
|
|
13
|
+
|
|
14
|
+
SyntaxError exposes the expression, a zero-based byte position, and one-based line and character column.
|
|
15
|
+
This distinguishes byte offsets from Unicode display positions.
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
JMESPath.search("length(@)", 7) # raises JMESPath::Errors::InvalidTypeError
|
|
19
|
+
JMESPath.search("unknown()", {}) # raises JMESPath::Errors::UnknownFunctionError
|
|
20
|
+
JMESPath.search("[::0]", []) # raises JMESPath::Errors::InvalidValueError
|
|
21
|
+
JMESPath.search("length(@)", 7, disable_visit_errors: true) #=> nil
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Only library argument-type and arity failures are suppressed by `disable_visit_errors`.
|
|
25
|
+
Syntax, unknown-function, invalid-value, adapter, and callback failures remain visible.
|
|
26
|
+
Missing fields and out-of-range indices normally return nil.
|
|
27
|
+
|
|
28
|
+
Invalid JSON streams raise the JSON parser's error class.
|
|
29
|
+
Invalid options raise ArgumentError.
|
|
30
|
+
The CLI translates expected input failures to status 1 and usage failures to status 2.
|