Show HN: gq – like jq or zq, but you use Go

Show HN: gq – like jq or zq, but you use Go

This is another fancy item!!

jq but using go instead.

go install

Or download the binaries here

Pipe some input into gq and pass in a block of go code as the argument. The variable j is set to the passed in JSON and printed at the end of the function, so manipulate it (e.g below) in order to change the output. The gq library is inlined in the program, and described in detail in the API reference above.


$ echo ‘{“weird”: [“nested”, {“complex”: “structure”}]}’ | gq ‘j.G(“weird”).I(1).G(“complex”)’


$ echo ‘[“list”, “of”, “mostly”, “uninterseting”, “good/strings”, “good/welp”]’ | gq ‘j.Filter(func(n *Node) bool { return strings.Contains(n.String(), “good/”) })’


$ echo ‘[1, 2, 3, 4]’ | gq ‘j.Map(func(n *Node) *Node {n.val=n.Int() + 50 / 2; return n})’

jq is hard to use. There are alternatives like fq and zq, but they still make you learn a new programming language. Im tired of learning new programming languages.

gq is not optimized for speed, flexibility or beauty. gq is optimized for minimal learning/quick usage. gq understands that you don’t use it constantly, you use it once a month and then forget about it. So when you come back to it, gq will be easy to relearn. Just use the builtin library just like you would any other go project and you’re done. No unfamiliar syntax or operations, or surprising limits. Thats it.

Speaking of surprising limits, gq runs your code in the yaegi go interpreter. This means that it runs quickly for small inputs/programs (the alternative was go run, which is… not quite as quick). However, it also means its not the fastest *q out there, and further it means that you might run into quirks with yaegi interpretation limitations. Seems to work pretty well so far though.

Yea, well, I built it last night, so, yea it kinda sucks. But please file issues! Or submit PRs! Maybe this will turn into something useful? At least maybe it will inspire some conversation.

I think it needs a lot of refinement still, in short.

Read More
Share this on to discuss with people on this topicSign Up on now if you’re not registered yet.

About the author: Charlie
Fill your life with experiences so you always have a great story to tell

Get involved!

Get Connected!
One of the Biggest Social Platform for Entrepreneurs, College Students and all. Come and join our community. Expand your network and get to know new people!


No comments yet
Knowasiak We would like to show you notifications so you don't miss chats & status updates.
Allow Notifications