Re:How to Use JSON Path
by stoperaticless on Friday May 03, 2024 @06:47AM
(#40246211)
Are you also against file paths?
[ Parent
| on HN ]
Re:How to Use JSON Path
by psnehanshu on Friday May 03, 2024 @07:22AM
(#40246390)
How's that related?
Re:How to Use JSON Path
by HarHarVeryFunny on Friday May 03, 2024 @07:51AM
(#40246593)
It's pretty much the exact same thing - let's you specify a file to access with a string (pathname) such as "/foo/bar/cat" rather than having to go step by step first open/reading directory "foo", then open/reading directory "bar", then finally accessing file "cat".
With XPath and JSONPath you're just dealing with DOM nodes and children rather than directories and children.
Except that XPath and JSONPath are overpowered. I'd welcome a simple standard path syntax for JSON, for instance, I'd want to use for reporting schema errors in JSON document ($.users[10].name must be a string). I can use JSONPath, sure, but even this subset is annoying to parse - compared to a filepath which you can parse with `path.split('/')`.
Re:How to Use JSON Path
by HarHarVeryFunny on Friday May 03, 2024 @09:56AM
(#40247715)
Agreed - for a lot of use cases all you need is a pathname-like way to refer to elements in the DOM, not a search/filtering mechanism.
You might like gron then.
https://github.com/tomnomnom/gron
For 90% on my needs this is all I need.