Add search_json(): query a JSON document given as a string, with optional native accelerator - #368
Open
SereinCin wants to merge 1 commit into
Open
Conversation
search_json(expression, data) queries a JSON document given as a string. When the optional aero-jmespath native accelerator is installed it runs parse + eval + serialize in native code; otherwise it falls back to json.loads() + search(). Purely additive: error behaviour is unchanged and no new dependency is required. Adds TestSearchJson coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
jmespath.search_json(expression, data)— search a JSON document given as a string.The common workflow for CLI tools, streams and HTTP handlers is:
search_json()does exactly that, and when the optional native acceleratoraero-jmespathis installed it runs the whole parse + eval + serialize pipeline in native code, skipping the Python-object round-trip:This is purely additive and backward compatible: without the accelerator the function falls back to
json.loads()+search(), so no behaviour changes and no new dependency is required. Error behaviour is identical in both paths (ValueError for bad JSON, ParseError for a bad expression).Benchmark
One-shot string-input pipeline (parse + eval + serialize per call), query
servers[?status == \active`].instances[0].idon a synthetic server fleet, Windows 11 / Python 3.12. Fully reproducible with the public benchmark repo [aero-jmespath-bench](https://github.com/SereinCin/aero-jmespath-bench) (python run_all.py`):The speedup grows with document size. Beyond this one-shot case the accelerator also offers a batch path (
aero_jmespath.multi) that parses one document once and evaluates many expressions against it (~1.75x in the benchmark), and its native JSON parser measures ~180 MB/s, faster thanorjson(1.36x) andjson.loads(1.70x) on the same document.The accelerator is a native (Aero-compiled) JMESPath kernel that passes all 578 official compliance tests.
Tests
tests/test_search.pygains aTestSearchJsoncase class covering field access, projections, empty documents, invalid JSON, and matchingsearch()on parsed documents. Full suite: 997 passed.