Show HN: JSON Query
154 points| wofo | 4 months ago |jsonquerylang.org
I like the power of `jq` and the fact that LLMs are proficient at it, but I find it right out impossible to come up with the right `jq` incantations myself. Has anyone here been in a similar situation? Which tool / language did you end up exposing to your users?
nothrabannosir|4 months ago
it's a pipeline operating on a stream of independent json terms. The filter is reapplied to every element from the stream. Streams != lists; the latter are just a data type. `.` always points at the current element of the stream. Functions like `select` operate on separate items of the stream, while `map` operates on individual elements of a list. If you want a `map` over all elements of the stream: that's just what jq is, naturally :)
stream of a single element which is a list:
unpack the list into a stream of separate elements: only keep elements 2 and 4 from the stream, not from the array--there is no array left after .[] : keep the array: map over individual elements of a stream instead: This is how you can do things like select creates a nested "scope" for the current element in its parens, but restores the outer scope when it exits.Hope this helps someone else!
tcdent|4 months ago
(LLMs are already very adept at using `jq` so I would think it was preferable to be able to prompt a system that implements querying inside of source code as "this command uses the same format as `jq`")
jonny_eh|4 months ago
inlined|4 months ago
cryptonector|4 months ago
movpasd|4 months ago
mrtimo|4 months ago
[1] - https://duckdb.org/docs/stable/data/json/overview [2] - https://www.malloydata.dev/
zie|4 months ago
gcr|4 months ago
I've observed that too many users of jq aren't willing to take a few minutes to understand how stream programming works. That investment pays off in spades.
MrApathy|4 months ago
penguin_booze|4 months ago
wpm|4 months ago
jawns|4 months ago
gnarlouse|4 months ago
aeberhart|4 months ago
unknown|4 months ago
[deleted]
Alifatisk|4 months ago
HatchedLake721|4 months ago
wofo|4 months ago
arccy|4 months ago
Just use jq. None of the other ones are as flexible or widespread and you just end up with frustrated users.
voidfunc|4 months ago
Which isn't to say jq is the best or even good but its battle-tested and just about every conceivable query problem has been thrown at it by now.
pscanf|4 months ago
I then switched to JavaScript / TypeScript, which I found much better overall: it's understandable to basically every developer, and LLMs are very good at it. So now in my app I have a button wherever a TypeScript snippet is required that asks the LLM for its implementation, and even "weak" models one-shot it correctly 99% of the times.
It's definitely more difficult to set up, though, as it requires a sandbox where you can run the code without fears. In my app I use QuickJS, which works very well for my use case, but might not be performant enough in other contexts.
cweagans|4 months ago
ccvannorman|4 months ago
am I missing something?
joshribakoff|4 months ago
To your point abstractions often multiply and then hide the complexity, and create a facade of simplicity.
eknkc|4 months ago
Things like https://jsonlogic.com/ works better if you wish to expose a rest api with a defined query schema or something like that. Instead of accepting a query `string`. This seems better as in you have a string format and a concrete JSON format. Also APIs to convert between them.
Also, if you are building a filter interface, having a structured representation helps:
https://react-querybuilder.js.org/demo?outputMode=export&exp...
throwaway091025|4 months ago
hyperhello|4 months ago
mapValues(mapKeys(substring(get(), 0, 10)))
This is all too cute. Why not just use JavaScript syntax? You can limit it to the exact amount of functionality you want for whatever reason it is you want to limit it.
kunley|4 months ago
Kudos for all the work, it's a nice language. I find writing parsers a very mind-expanding activity.
memelang|4 months ago
gnarlouse|4 months ago
Admittedly I don't know that much about LLM optimization/configuration, so apologies if I'm asking dumb questions. Isn't the value of needing to copy/paste that prompt in front of your queries a huge bog on net token efficiency? Like wouldn't you need to do some hundred/thousand query translations just to break even? Maybe I don't understand what you've built.
Cool idea either way!
peterohler|4 months ago
tyre|4 months ago
Helpful when querying JSON API responses that are parsed and persisted for normal, relational uses. Sometimes you want to query data that you weren’t initially parsing or that matches a fix to reprocess.
lenkite|4 months ago
thayne|4 months ago
[1]: https://datatracker.ietf.org/doc/html/rfc9535
cmckn|4 months ago
nartho|4 months ago
voidfunc|4 months ago
miohtama|4 months ago
ksclarke|4 months ago
ivanjermakov|4 months ago
I implemented one day of advent of code in jq to learn it: https://github.com/ivanjermakov/adventofcode/blob/master/aoc...
hk1337|4 months ago
linhns|4 months ago
emadda|4 months ago
npodbielski|4 months ago
gabrielsroka|4 months ago
roxolotl|4 months ago
gfody|4 months ago
unknown|4 months ago
[deleted]
ifh-hn|4 months ago
[deleted]