News for hackers. Stuff that matters.
Re:Gron – Make JSON Greppable by jeffbee on Friday November 06, 2020 @09:24AM (#25007761)
It feels like finding a deeply nested key in a structured document is a job for XPath. Most people including myself until recently ignore that XPath 3.1 operates on JSON.
Re:Gron – Make JSON Greppable by specialist on Friday November 06, 2020 @04:13PM (#25011220)
FWIW, my two cents:

I like that jq's query expression syntax is command line (bash) friendly. My hunch is that xpath expressions would be awkward to work with.

I've done too much xpath, xquery, xslt, css selectors. For my own work (dog fooding), I settled on mostly using very simple globbing expressions. Then use the host language's 'foreach' equiv for iterating result sets.

Globbing's double asterisk wildcard is the feature I most miss in other query engines. https://en.wikipedia.org/wiki/Glob_%28programming%29

Looping back to command line xpath: there's always some impedance match between the query and host languages. IIRC, one of the shells, like chubot's oilshell or fish?, has more rational expression evaluation (compared to bash).

You especially see this with regexs. It's a major language design fail that others haven't adopted Perl's first class regex intrinsics. C# has LINQ, sure. But that's more xquery than xpath. And I've never liked xquery.

In other words, "blue collar" programming languages should have intrinsic path expressions. Whatever the syntax.

YMMV.

Re:Gron – Make JSON Greppable by fiddlerwoaroof on Friday November 06, 2020 @11:19AM (#25008727)
Is there a command line tool that supports XPath on JSON?
Re:Gron – Make JSON Greppable by jeffbee on Friday November 06, 2020 @11:40AM (#25008930)
Yes, xidel. The author hangs out here.
Re:Gron – Make JSON Greppable by vibrant_mclean on Friday November 06, 2020 @04:32PM (#25011389)
I use xmllint for html and xml. I don't think it supports json
Re:Gron – Make JSON Greppable by NelsonMinar on Friday November 06, 2020 @01:51PM (#25010088)
Most people ignore XPath.