Top
Best
New

Posted by wofo 2 days ago

Show HN: JSON Query(jsonquerylang.org)
I'm working on a tool that will probably involve querying JSON documents and I'm asking myself how to expose that functionality to my users.

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?

147 points | 68 commentspage 2
ccvannorman 2 days ago|
I can't help myself and surely someone else has already done the same. But the query

  obj.friends.filter(x=>{ return x.city=='New York'})
  .sort((a, b) => a.age - b.age)
  .map(item => ({ name: item.name, age: item.age }));
does exactly the same without any plugin.

am I missing something?

joshribakoff 2 days ago|
The verbosity.

To your point abstractions often multiply and then hide the complexity, and create a facade of simplicity.

kunley 2 days ago||
Lot of people focus on a similarity to jq et al, I guess the author had his reasons to craft own stuff.

Kudos for all the work, it's a nice language. I find writing parsers a very mind-expanding activity.

eknkc 2 days ago||
Most alternatives being talked about are working on query strings (like `$.phoneNumbers[:1].type`) which is fine but can not be easily modeled / modified by code.

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 2 days ago|
JSON logic is nice, but for example, the Python bindings were last updated 8 years ago
hyperhello 2 days ago||
.friends | filter(.city == "New York") | sort(.age) | pick(.name, .age)

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.

memelang 2 days ago||
I've been working on an ultra-token-efficient LLM-friendly query language. https://memelang.net/09/
gnarlouse 2 days ago|
Cool idea! Although without looking closer I can't tell if "meme" is in reference to the technical or the colloquial meaning of meme.

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!

memelang 2 days ago||
Thank you. That script prompt is just for development and exploration. A production model needs to be trained/fine-tuned on Memelang first. We're working on this now. The math says we can deliver a model 1/2 the size of an equivalent model for SQL.
peterohler 2 days ago||
If you prefer JSONPath as a query language, oj from https://github.com/ohler55/ojg provides that functionality. It can also be installed with brew. (disclaimer, I'm the author of OjG)
tyre 2 days ago|
JSONPath is also supported by Postgres!

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.

Eric_WVGG 2 days ago||
speaking of classic databases: can anyone explain to me, a dummy, why any syntax like this or even GraphQL is preferable to "select a.name, a.age from friends a where a.city = 'New York' order by a.age asc"?
lenkite 2 days ago||
There are a ridiculous number of JSON query/path languages. Wish all the authors got together and harmonized on a standard.
thayne 2 days ago||
There is a standard in RFC 9535 (JSONPath)[1]. But as far as I can tell, it isn't very widely used, and it has more limited functionality than some of the alternatives.

[1]: https://datatracker.ietf.org/doc/html/rfc9535

lelandbatey 2 days ago|||
Don't forget the also standardized way of referring to a single value in JSON, "JSON Pointer": datatracker.ietf.org/doc/html/rfc6901
phpnode 2 days ago||||
the issue with JSONPath is that it took 17 years for it to become a properly fleshed-out standard. The original idea came from a 2007 blog post [0], which was then extended and implemented subtly differently dozens of times, with the result that almost every JSON Path implementation out there is incompatible with the others.

[0] https://goessner.net/articles/JsonPath/

NewJazz 2 days ago|||
Postgresql supports jsonpath, right?
Groxx 2 days ago||
SQLite might too, though I'm struggling to find anything explicit about the syntax: https://sqlite.org/json1.html#jptr

it might just be a very limited subset?

NewJazz 2 days ago||
Looks like "JSON Pointer": datatracker.ietf.org/doc/html/rfc6901
thayne 2 days ago||
JSON pointer uses very different syntax. Sqlite looks like it uses something that is very similar to, but not quite compatible with, JSONPath.
cmckn 2 days ago|||
The AWS CLI supports JMESPath (https://jmespath.org) for the `--query` flag. I don't think I've run into anything else that uses it. Pretty similar to JSONPath IIRC.
gegtik 2 days ago||
azure tools also support JMESPath
nartho 2 days ago|||
Plus, I feel like most, if not all, higher level languages already come with everything you need to do that easily. Well except for go that requires you to create your own filter function.
voidfunc 2 days ago|||
The standard is called jq, any new standard is just going to be a committee circle jerk that doesn't move the ball forward in any meaningful way.
lenkite 2 days ago||
jq is good but its syntax is strangely unmemorizable. Have used it for a decade and always need to look at the manual or at examples to refresh my knowledge.
miohtama 2 days ago||
Xkcd.gif
ksclarke 2 days ago||
https://www.jsoniq.org -- jq is ubiquitous, but I still prefer the jsoniq syntax.
ivanjermakov 2 days ago||
jq is amazing (not only for querying json), I recommend going though the docs, it's fairly small.

I implemented one day of advent of code in jq to learn it: https://github.com/ivanjermakov/adventofcode/blob/master/aoc...

hk1337 2 days ago|
What do your users know? If they’re quite familiar with SQL for querying, I would look at duckdb.
More comments...