ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Jq

by Jiehong ST3

Jq wrapper plugin for Sublime Text 3 & 4. It mainly lets you craft jq queries interactively, or run any jq queries via a keyboard shortcut.

Labels interactive, jq, json

Details

Installs

  • Total 121
  • Win 37
  • Mac 75
  • Linux 9
Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28 Aug 27 Aug 26 Aug 25 Aug 24 Aug 23 Aug 22 Aug 21 Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9
Windows 1 0 2 0 0 0 1 0 1 0 1 3 1 4 0 0 1 1 0 1 2 1 0 1 0 0 1 0 1 1 1 0 2 2 1 0 3 1 0 0 2 2 1 0 0
Mac 0 3 1 1 1 1 3 2 4 2 1 0 3 5 0 1 0 1 0 0 2 0 4 3 0 0 1 6 0 1 1 0 3 2 3 2 4 1 0 0 5 8 2 0 0
Linux 1 0 0 0 0 1 0 1 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 2 0 1 0 0

Readme

Source
gitlab.​com

Sublime Jq

jq wrapper for Sublime Text 3 & 4.

It gives you jq in the best of ways:

  1. Interactively construct a jq query with live update
  2. Format a JSON document (pretty print or make it compact)
  3. Run pre-defined jq queries on any json document

Installation

Via Package Control

Install it from packagecontrol.io to benefit from automatic updates.

Manual

Clone this repository in your Sublime Package directory (Find it in “Preferences” and then “Browse Packages”).

Requirements

This plugin does not work on its own. It completely depends on jq.

Therefore, before using this plugin, you must have installed jq, and you must ensure that jq is in your PATH.

That's it!

How to use it

Interactively transform JSON with a jq query

Within a given tab, start the Sublime Command Palette with Ctrl + Shift + p, and search for jq: Transform JSON.

An input panel will be displayed at the bottom, and your JSON will be transformed on the fly while you write your jq query.

If you aren't happy with your query, you can cancel it at anytime with Escape, and the content of your tab is reverted to its original content.

Format JSON

Within a given tab, start the Sublime Command Palette with Ctrl + Shift + p, and search for jq: Format JSON.

Your tab content will be replaced with the formatted/pretty-printed json.

Format JSON: compact

Within a given tab, start the Sublime Command Palette with Ctrl + Shift + p, and search for jq: Format JSON (compact).

Your tab content will be replaced with the formatted json as a 1-liner.

Commands Documentation

jq_format_json

Given a tab, pretty prints its json content. Runs jq '.' to do so.

Example:

view.run_command("jq_format_json")

Available in the command pallete.

jq_format_json_compact

Given a tab, format its json content on 1 line. Runs jq --compact-output '.' to do so.

Example:

view.run_command("jq_format_json_compact")

Available in the command pallete.

jq_transform_json

Given a tab, starts an interactive session to transform its json content. Lets you run jq 'query' interactively.

Example:

view.run_command("jq_transform_json")

Available in the command pallete.

jq_apply_query

Given a tab, applies a pre-defined jq query to its content. This is useful if you often process a json the same way, or if you want to set a shortcut to it.

Example (pretty print with sorted keys):

view.run_command("jq_apply_query", {"query": ".", "sort_keys": True})

Same example, but assigns the keyboard shortcut Super + j to it:

{ "keys": ["super+j"], "command": "jq_apply_query", "args": {"query": ".", "sort_keys": True} },

jq_apply_query accepts the following arguments:

  • query: the jq query as a string
  • compact: True or False (default). Corresponds to jq --compact-output
  • slurp: True or False (default). Corresponds to jq --slurp
  • sort_keys: True or False (default). Corresponds to jq --sort-keys
  • raw_in: True or False (default). Corresponds to jq --raw-input
  • raw_out: True or False (default). Corresponds to jq --raw-output

Unavailable in the command pallete, only available as a command in the console or when assigned as a keyboard shortcut.