jq-zsh-plugin
jq-zsh-plugin copied to clipboard
jq zsh plugin
jq zsh plugin
Interactively build jq expressions (gojq is also supported).
This zsh plugin gives you jq superpowers!
Table of contents
- Installation
- Usage
- Key bindings
-
Demos
- Interactive jq query construction
- Insert jq query in the middle of a pipeline
Installation
This plugin requires fzf to be available on your PATH.
The project consists of the following components:
- a
jq-repl
command - a
jq-paths
command - a
jq.plugin.zsh
providing line-editor feature utilizingjq-repl
zplug
zplug reegnz/jq-zsh-plugin
Antigen
antigen bundle reegnz/jq-zsh-plugin
Zgen
zgen load reegnz/jq-zsh-plugin
Usage
- type out a command that you expect to produce json on it's standard output
- press alt + j and interactively write a jq expression
- press enter, and the jq expression is appended to your initial command!
Key bindings
To bring up the JQ query builder, press alt + j
.
During interactive querying, the following shortcuts can be used:
Shortcut | Effect |
---|---|
up |
Navigate path queries |
down |
Navigate path queries |
tab |
Select path query |
shift + up |
Scroll up |
shift + down |
Scroll down |
alt + up |
Scroll up full page |
alt + down |
Scroll down full page |
ctrl+r |
Reload input |
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, by setting the following environment variable:
JQ_REPL_JQ=gojq
Demos
Interactive jq query construction
Insert jq query in the middle of a pipeline
Troubleshooting
MacOS: Pressing alt-j creates a ∆
symbol in iTerm2
You need to remap your alt-key to Esc+
in iTerm2:
-
Cmd + ,
to enter preferences - Go to Profiles
- select your profile from the pane on the left hand side
- go to the keys tab
- Set Left Option (⌥ ) Key to
Esc+
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