Hacker News new | ask | show | jobs
by xd 908 days ago
I've a similar way of interacting with the API of my product but instead keep everything prefix notation (lispy) so for example;

"and": [ { "property": "material", "operator": "equals", "value": "carbon" },

Would be;

["and", ["=", "material", "carbon"], ...]

3 comments

Is there any standard for describing filters in json like this, or any well known library that is also able to parse this back to expressions?
In my humble opinion, it would benefit all better if we standardized something like jql (jira query language, so the user layer) first. From experience, many who find sql too complex have no problem with writing complicated jql queries. it's both easy to use and a great first step to writing actual SQL. I wish it was a standard like json.
The first thing that came to my mind is the mapbox espression language/spec, which uses a very similar format:

https://docs.mapbox.com/style-spec/reference/expressions/

The way the JSON filters work would be directly coupled to the JSON fix notation and SQL infix notation so it's directly coupled to SQL and doesn't really require a standard, imho.
If you're reinventing a language, it's probably not a bad idea to reinvent the simplest one!
Just wondering, why order =, material, and carbon that way instead of material, =, carbon?
It's "prefix" notation .. if you search something like "prefix vs infix vs postfix programming languages" it should return a decent explanation. For my case it's personal choice more than anything.. also easier for me to write a VM for.