Hacker News new | past | comments | ask | show | jobs | submit login
Jqp – A TUI playground for exploring jq (github.com/noahgorstein)
240 points by Shank on Sept 19, 2022 | hide | past | favorite | 27 comments



When I am hacking something relatively simple together, I tend to do:

echo '' | fzf --preview 'jq {q} < filename.json'

This approach can be generalized to other tools, to some extent: https://github.com/pawelduda/fzf-live-repl


You kind of blew my mind with this simple concept. Going to see if I can incorporate it in my #kitbag


Oh woah, love this. Thanks for sharing. Will definitely be giving it a try.


can you explain what exactly is happening here


fzf is an interactive tool for fuzzy-finding and will take input from stdin. For example, `ls | fzf` will allow you to search through a list of files in your working directory. It also has an optional preview pane that can be used to show the output of a command.

In this case, the empty string is provided as input because we're not interested in selecting options. You can then type your jq filter in fzf's query box and the command will run against filename.json in the preview pane on every kepress (the {q} is your currently typed query).


Very nice! For something quick and dirty (and `apt-get install`able), I usually use jq+fzf like this: https://gist.github.com/reegnz/b9e40993d410b75c2d866441add2c...


Another useful json explorer TUI - jless.

https://jless.io/



This is awesome!

I sometimes use jiq for this purpose, but I don't like that it tries to evaluate the query as you type, pressing enter exits the interactive session, and that you can't see the source and output at the same time. Jid has similar issues.

Jqp seems to solve all of these problems, plus it has syntax highlighting. I'm going to use this tool all the time.


I've played with jid in jiq and IIRC they were very slow with large inputs since they re-parse the JSON blob every time the query changes. I wonder if this solves that problem--I'll bookmark it and find out next time I need to wrangle some JSON!


wow, thanks so much for the kind words! Didn't think people would see this, let alone for it to show up on Hacker News haha. Hope you get a lot of use out of it!


A feature that would be cool:

I often write some pretty complex jq queries. Once a query starts getting complex, I like to spread it over multiple lines for better readability. It would be cool if Jqp would let me insert newlines by pressing Shift+Enter.


Yeah for sure! Initially I had tried to do something like this, hit a roadblock and just went with the 1 line input in order to get a v1 out. Definitely something I'd consider as I continue to iterate on it.


I had fun writing a tree-sitter grammar[1] for jq, mostly based on the gojq parser. I realized it was probably in pretty good shape when a snippet that I thought was valid had a syntax error, which tree-sitter was happy to confirm. jq is a lot of fun to write and think with, and the stdlib is good but quirky. It would really benefit from some more libraries, so it's great to see tools to facilitate writing in it!

[1] https://github.com/flurie/tree-sitter-jq


I’m loving this resurgence of TUI apps. Only now the quality and cross compatibility is much better than in the 90’s.

Keep ‘em coming.


What would be really awesome (although likely means ripping apart jq) would be some intermediate query caching. I often browse through large-ish (~1-2GB) JSON files and do something similar to the example animation in that I repeatedly filter and look for something. It would be awesome if it were smart enough to reasonable cache "filter A" when later reasoning about "filter A and filter B".

Still really great as-is, will definitely use it.


Have you tried VisiData for this?


I have not, but I will investigate - cheers!


I use ijq [1], saves me a lot of time.

[1] https://sr.ht/~gpanders/ijq/


Please include scoop installation for your tool. Sincerely, a lazy user on the Internet.


TUI = Training user environment?


TUI = Terminal User Interface


Wow cool.

This really makes me want TUIs for many other clis.


I don’t know what any of those words mean.


jq is a tool that can query (search/extract/format) JSON (JavaScript readable data files).

I figured from the README that TUI probably stands for Text User Interface as it seems to support keystrokes in a way that an editor like Vi or Emacs work in a terminal (yeah I hadn't of it either, but I guess it is a retro acronym from GUI which is more well known)


And 'playground' often refers to interactive code environments, like this one for trying out tree-sitter parsing:

https://tree-sitter.github.io/tree-sitter/playground


TUI is anything sorta graphical and interactive in a terminal. Often but not always ncurses stuff.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: