Home

Awesome

jq zsh plugin

Interactively build jq expressions (gojq is also supported).

This zsh plugin gives you jq superpowers!

Fish users: you can use this friendly fork: rmartine-ias/jq-fish-plugin

Table of contents

Demos

Interactive jq query construction

asciicast

Insert jq query in the middle of a pipeline

asciicast

Installation

Besides jq, this plugin also requires fzf (a recent version) to be installed and available on your PATH.

The following installation methods are proven to work:

Oh My Zsh

  1. Clone the repository:
git clone https://github.com/reegnz/jq-zsh-plugin.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/jq
  1. Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):
plugins=(
	# other plugins...
	jq
)
  1. Start a new terminal session.

zplug

zplug reegnz/jq-zsh-plugin

Antigen

antigen bundle reegnz/jq-zsh-plugin

Zgen

zgen load reegnz/jq-zsh-plugin

Usage

Key bindings

Bringing up the jq query builder for a shell command: alt + j

During interactive querying, the following shortcuts can be used:

ShortcutEffect
ctrl-k or upNavigate path queries
ctrl-j or downNavigate path queries
tabSelect path query
ctrl-p or shift-upScroll up
ctrl-n or shift-downScroll down
ctrl-alt-pScroll up half page
ctrl-alt-nScroll down half page
alt-upScroll up full page
alt-downScroll down full page
ctrl-rReload input
ctrl-yYank selected path to clipboard (GNU/Linux only)

gojq support

If you want to use an alternative jq implementation, like gojq then you can override the default jq command used by the plugin. Set the following environment variable:

JQ_REPL_JQ=gojq

Internals

The project consists of the following components:

Troubleshooting

MacOS: Pressing alt-j creates a symbol in iTerm2

You need to remap your alt-key to Esc+ in iTerm2:

See other suggestions on stackoverflow if the above one doesn't help you: https://stackoverflow.com/q/196357/205318

Another option is to map to ctrl+j instead by putting this in your .zshrc:

bindkey `^j` jq-complete

Disable expanding shell aliases

The plugin automatically expands shell aliases in a command before passing it to jq-repl. To disable, put the following line into your .zshrc:

JQ_ZSH_PLUGIN_EXPAND_ALIASES=0