A Common Lisp jq replacement
Title says it all, I seriously dislike jq's convoluted,
impossible-to-remember ad hoc DSL that instantly joined heaps of misery like CMake and
gnuplot in my heart. It should really have been a library with a CLI wrapper around eval
in a well-known scripting language like Python.
And I'm not the only one I've heard complain about this, yet it's the one that seized the mindshare and thus became easy to find in any package repository (sometimes even preinstalled) and with the most copy-paste fodder on the web. It won for the usual reasons: lack of serious competition at the time, enough flexibility to manage most tasks with enough pain and elbow grease and now inertia.
But me, I've reached my enough is enough!
point and decided to do like VapourSynth or waf and replace it with a language I know and love: CL.
For now, cljq is only a very
bare-bones pipeline that parses a JSON (argv or stdin) into a variable $
, eval
an arbitrary CL form and serializes the result to stdout (using jzon). But the query operator ?
inspired by JSONPath is already an improvement, in my eyes:
$ json='{"root": {"a": [0, 1], "b": [2, 3]}}' $ echo "$json" | jq '.root | map(.[1])' [ 1, 3 ] $ echo "$json" | cljq '(? $ "root" * 1)' [ 1, 3 ]
Here's a small JSONPath <=> ?
correspondance table (using some examples found in
the aforementioned RFC):
JSONPath | cljq's ? |
---|---|
$.store.book[*].author | (? $ "store" "book" * "author") |
$..author | (? $ ** "author") |
$.store.* | (? $ "store" *) |
$.store..price | (? $ "store" ** "price") |
$..book[-1] | (? $ ** "book" -1) |
$..book[0,1] | (? $ ** "book" (or 0 1)) |
$..book[0:2] | (? $ ** "book" (subseq 0 2)) |
That's it for now; the README has a TODO section, if you want an idea of what's coming.
Anyone else rocking homegrown tools to fight the proliferation of crappy DSLs? Write an article about it and send me an email, I'll link it!