jnv: An Interactive JSON Viewer and jq Filter Editor for Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

I assume you are aware of jq (a JSON processor to parse and manipulate JSON data right from your command line), and recently we have also written an article on jaq (a superset of jq with additional features and improved performance), but today we bring to you a new tool named jnv.

What is jnv?

jnv is a CLI tool that works like jq and inherits all the functionality of jq but offers a unique interactive JSON viewer and jq filter editor to apply and view changes instantly.

If you’re familiar with jq, transitioning to jnv requires no learning curve; it allows you to interact more dynamically with your JSON data and apply filters effortlessly, making it the best choice while working with the API, AWS CLI tool, Ansible, or Kubernetes.

This article will focus on the installation of jnv on your preferred Linux distribution, with a few examples of usage. If you are very new to the topic of jnv, jq, or JSON processing, you might be unaware of the concept of filters used in them to slice, filter, map, and transform structured JSON data. So, do check out this quick and crisp jq cheatsheet.

How to Install jnv on Linux

The installation of jnv is quite annoying; firstly, it’s not available in the Linux repository, and the options it offers are Cargo and Brew. I suggest using Brew to install it on Linux or macOS and trying to avoid Cargo, as you might encounter an error.

$ brew install jnv                                                                             #On Linux or macOS via Brew
$ cargo install jnv                                                                            #Via Cargo Package Manager
$ sudo port install jnv                                                                     #On macOS via Port
$ nix-shell -p jnv                                                                              #On NixOS

Once the installation is finished, the β€œjnv” command will become accessible, and don’t worry, you don’t need to install jq separately as it relies on j9 Rust bindings.

Usage of jnv

Once the installation is complete, you can use it to view JSON files in two different ways. For example, if you have a β€œdata.json” file, you can view it in the following two ways:

$ cat data.json | jnv

#OR

$ jnv data.json

However, if you have an API, you can make a first request using the curl command and then pipe the stdout data to jnv stdin.

$ curl https://api.github.com/users/octocat | jnv

Output:

jnv command output

From the jnv interface, you can use β€œUp” and β€œDown” arrows key to go through with each entry in the output, β€œTab” key to auto complete, or the β€œEnter” key to expand/collapse in JSON viewer.

At the top of the jnv interface, you’ll find the jq filter editor, which allows you to slice, filter, map, and transform structured JSON data in real-time.

As you can see, it works almost like jq and allows for more interaction with JSON data. Almost all the functionality is the same; you can apply filters and see the results in real-time. All you need to learn are a few keybindings, which are provided below.

KeyAction
Ctrl + CExit jnv.
Tabjq filter auto-completion.
←Move the cursor one character to the left.
β†’Move the cursor one character to the right.
Ctrl + AMove the cursor to the start of the filter.
Ctrl + EMove the cursor to the end of the filter.
BackspaceDelete a character of the filter at the cursor position.
Ctrl + UDelete all characters from the filter.
↑, Ctrl + KMove the cursor one entry up in the JSON viewer.
↓, Ctrl + JMove the cursor one entry down in the JSON viewer.
Ctrl + HMove to the last entry in the JSON viewer.
Ctrl + LMove to the first entry in the JSON viewer.
EnterToggle expand/collapse in the JSON viewer.
Ctrl + PExpand all folds in the JSON viewer.
Ctrl + NCollapse all folds in the JSON viewer.
Alt + BMove the cursor to the previous nearest character within set(.,|,(,),[,]).
Alt + FMove the cursor to the next nearest character within set(.,|,(,),[,]).
Ctrl + WErase to the previous nearest character within set(.,|,(,),[,]).
Alt + DErase to the next nearest character within set(.,|,(,),[,]).

Once you’re familiar with the above keybindings, you’re good to use jnv instead of jq, as everything is almost the same. Here, I’ll end this article, but if you have any queries or questions related to the topic, then do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.