News for hackers. Stuff that matters.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by EdSchouten on Tuesday January 07, 2020 @02:28PM (#21983717)
So I guess we all know https://jsonnet.org, right? It's advertised as a data templating language. Interestingly enough, you can also use it as a querying tool. The first four examples on the jql page can be translated to Jsonnet as follows:

    $ jsonnet -e "(import 'test.json').countries[0]"
    $ jsonnet -e "(import 'test.json').countries[0:2]"
    $ jsonnet -e "[x.name for x in (import 'test.json').countries]"
    $ jsonnet -e "std.objectFields((import 'test.json').countries[0])"
With that in mind, I never bothered to learn how to use a tool like jq, rq, jql, etc.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by hnlmorg on Tuesday January 07, 2020 @03:25PM (#21984406)
Shameless plug but I've also written a language (murex) for shell scripting which can be used for this too:

    open test.json -> [ countries ]
    open test.json -> [[ /countries/0 ]]
    open test.json -> [ countries ] -> [ 0 2 ]
Single brackets only return the next level deep but can retrieve multiple items (and negative integers to count from the end of an array). Double brackets are to specify a path. So [[/foo/bar]] is literally the same as [foo]->[bar]

Lastly the 4th example:

    open test.json -> [ countries ] -> foreach c { echo $c[name] }
Unfortunately this one doesn't output it in JSON. If you needed that you could chain another command to reformat it:

    open test.json -> [ countries ] -> foreach c { echo $c[name] } -> cast str -> format json
This works because murex can auto-convert between lists, JSON, YAML, CSV and a few other structured formats. However it's fair to say it is a lot more verbose than jsonnet and jql in that last example.

Github repo: https://github.com/lmorg/murex

I've been using this as my primary shell for a few years now and, like yourself, I've never bothered to learn jq because of that.

NB all of the above example are running from inside the murex interactive command line (like bash). If you wanted to run it like jq/jql then you'd need to do the same sort of thing as bash:

    murex -c 'open test.json -> [ countries ]'
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by FragenAntworten on Tuesday January 07, 2020 @04:52PM (#21985356)
Another option which looks interesting: https://github.com/jmespath/jp

I haven't used it yet, but the syntax seems simpler than some.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by edaemon on Tuesday January 07, 2020 @05:44PM (#21985974)
Thanks for the link, this straightforward syntax is what I've been after for dealing with JSON on the command line.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by iudqnolq on Wednesday January 08, 2020 @02:52AM (#21989284)
Wow! Thank you so much for showing me this.

I never before wanted to write object oriented JSON, but now my mind has been opened.

For those who haven't yet seen it/opened the link, it's 20% project that describes itself as:

> A data templating language for app and tool developers

- Generate config data

- Side-effect free

- Organize, simplify, unify

- Manage sprawling config

> A simple extension of JSON

- Open source (Apache 2.0)

- Familiar syntax

- Reformatter, linter, editor & IDE integrations

- Formally specified

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by EdSchouten on Wednesday January 08, 2020 @03:22AM (#21989464)
Yeah. It’s a pretty sweet tool. What’s also pretty awesome about it is that its interpreters (one C++ and one Go implementation) can also easily be embedded into custom applications.

For an Open Source project of mine (https://github.com/buildbarn, a remote build cluster implementation for the Bazel build system), we are using go-jsonnet as the config file parser library. This means that people can use JSON, but if they need something that’s more flexible, they can add Jsonnet statements immediately. It’s also possible to have that as a preprocessing stage (init scripts), but in a containerized world it’s easier to have it embedded.

One of the nice things about doing that is that I also don’t need to write code to load TLS certificate data from disk. People can either embed their secrets directly into the config file, or they can use Jsonnet’s ‘importstr’ keyword to load separate PEM files from disk.

Somewhat related to that: Jsonnet also allows people to write libraries for constructing more complex JSON files. For example, the Grafana folks have released a library (https://github.com/grafana/grafonnet-lib) that allows you to easily build Grafana dashboards from code.

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by iudqnolq on Wednesday January 08, 2020 @03:51AM (#21989644)
> This means that people can use JSON, but if they need something that’s more flexible, they can add Jsonnet statements immediately.

That sounds awesome. I'd expect it's worth it just to have self and $.

And not only that, jsonnet can also produce yaml and ini files. I might try using it to configure my whole machine...

Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by krick on Tuesday January 07, 2020 @10:50PM (#21988104)
Wow. No, we all didn't know jsonner.org, and, TBH, it was always a problem for me to remember jq syntax every time I needed to do something. This really looks perfect, thanks!
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by cube2222 on Tuesday January 07, 2020 @02:42PM (#21983905)
This is actually the best alternative to jq for me I've seen so far! (other than jql obviously ;) ) Thanks for posting!
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by jaib8 on Tuesday January 07, 2020 @04:40PM (#21985219)
I haven't used jsonnet before but is it possible to read via stdin? for eg to parse a json response from a rest endpoint in jq I would do something like: $ curl "..." | jq .abc
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by ljm on Tuesday January 07, 2020 @05:53PM (#21986072)
My favourite is yq, because there are two competing and utterly incompatible implementations of it. Just to add onto the shitshow that YAML can be.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by Maxious on Tuesday January 07, 2020 @06:03PM (#21986194)
brew install yq vs. brew install python-yq always gets me
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by paulddraper on Tuesday January 07, 2020 @09:01PM (#21987511)
jsonnet is more verbose (especially with that import syntax), but scales well, with separate files, functions, etc.
Re:Show HN: jql – Easier jq Alternative with a Lispy Syntax ... by theamk on Tuesday January 07, 2020 @05:01PM (#21985475)
> Language Reference

> TODO: This page still needs to be written.

Looks like it is not ready for prime time yet... (Not to mention that it seems to have no support for stdin input, multiple input files, and json lines format - which are my main uses cases for jq)