3 ms·
jmespath is your friend for this import jmespath import json doc = json.load(sys.stdin) print(jmespath.search("[?commit.author == `Tom Hudson`
by Spivak 3y ago
jmespath is your friend for this
import jmespath
import json
doc = json.load(sys.stdin)
print(jmespath.search("[?commit.author == `Tom Hudson`].commit", doc))
I wish it had won over jq because JMESPath is a spec with multiple implementations and a test suite where jq is... well jq and languages have bindings not independent implementations.
- cryptonector 3y ago`import jmespath` is a lot like importing jq... > I wish it had won over jq because JMESPath is a spec with multiple implementations and a test suite where jq is... well jq and languages have bindings not independent implementations. jq has multiple implementations too! In Go, Rust, Java, and... in jq itself.
- Spivak 3y agoSo just picking Java https://github.com/eiiches/jackson-jq https://github.com/eiiches/jackson-jq > jackson-jq aims to be a compatible jq implementation. However, not every feature is available; some are intentionally omitted because thay are not relevant as a Java library; some may be incomplete, have bugs or are yet to be implemented. Where JMESPath has fully compliant 1st party implementations in Python, Go, Lua, JS, PHP, Ruby, and Rust and fully compliant 3rd party implementations in C++, Java, .NET, Elixer, and TS. Having a spec and a test suite means that a all valid JMESPath programs will work and work the same anywhere you use it. I think jq could get there but it doesn't seem to be the project's priority.
- rtpg 3y agojmespath does look like an interesting thing. Wish it weren't stringly-typed but that is a bit unavoidable.
- HelloNurse 3y agoRepeating an identifier like this is inelegant, it should be (untested) commit|[?author == `Tom Hudson`]