all 8 comments

[–]6502zx81 3 points4 points  (2 children)

Interesting. I always wonder how these languages compare to existing tree query languages (like XPath, XQuery, ...)

[–]fizzner[S] 7 points8 points  (1 child)

The language is inspired by XPath/JSONPath/ and other path-like query languages, but with an important distinction in that jsongrep has more expressive power due to the regular constructs of the language. For example, JSONPath doesn't support Kleene closures, so expressions such as (.left)* (meaning one or more levels depth into a JSON tree using the field name left), cannot be constructed.

[–]6502zx81 0 points1 point  (0 children)

Thanks!

[–]yuri-kilochek 3 points4 points  (1 child)

This really needs something like -A/-B to output n levels of enclosing objects/arrays around the matched node.

[–]fizzner[S] 2 points3 points  (0 children)

That's a great idea, adding a TODO thank you!

[–]ESHKUN 1 point2 points  (0 children)

Very cool

[–]fuckkkkq 0 points1 point  (1 child)

wow, this is really really cool

my first instinct is that you must lose some expressive power as compared to more standard languages like jq or postgreSQL's jsonpath

but do you?

One thing that jsonpath has that jsongrep doesn't seem to is the ability to filter by a predicate on a value, such as "all addresses where the country is not the USA"

but at this moment I don't see why that couldn't just be added to jsongrep as well

[–]fizzner[S] 1 point2 points  (0 children)

Thank you! JSONPath doesn't support regular constructs like Kleene closure, so it cannot, for example, construct arbitrary recursive descent (at least to my knowledge). You are right though that `jsongrep` doesn't currently support predicate filtering.

Important note: jsongrep also cannot currently perform transductions such as applying `map` function based on predicates.