Re:jq 1.7 released
by ahoka on Thursday September 07, 2023 @06:36AM
(#37417016)
What about JSONPath?
[ Parent
| on HN ]
It may be fine for hello-world stuff, but how would one JSONPath this?
echo '[{"name":"_skip"},{"name":"alpha"},{"name":"_other"}' | \
jq '[ .[] | select(.name|test("^_.*")|not) | . ]'
The same is roughly true for JMESPath, also, although at least it does actually try to allow projections and some limited functionsIs ".*" necessary? I think "^_" should be enough.
I believe like this.
$[?(@.name =~ /[^_].*/)]Interesting, I only knew about <https://goessner.net/articles/JsonPath/index.html> which makes no reference to =~ nor any such // syntax but it seems there's an IETF draft that is (a) an actual specification (b) includes more modern stuff like what you used: https://www.ietf.org/archive/id/draft-ietf-jsonpath-base-07....
And, while whatever is powering https://jsonpath.com/ does honor your syntax, albeit with an absolutely useless result:
[
{
"name": -1
},
{
"name": -1
},
{
"name": -1
}
]
I found that `pip install jsonpath-ng` does not accept it nor mention it <https://github.com/h2non/jsonpath-ng/tree/v1.5.3?tab=readme-...> so I think it's out on the bleeding edge or something
Re:jq 1.7 released
by hn92726819 on Friday September 08, 2023 @01:42PM
(#37436841)
I hadn't seen this before. At a quick glance, the syntax looks fine. Though I don't know what command line utility I'd need to use it. It makes me wonder how hard a translator from jq syntax to jsonpath would be... Then we could have our cake and eat it too.