jless — a command-line JSON viewer

Usage

jless can read files directly, or read JSON data from standard input:

$ curl https://api.github.com/repos/PaulJuliusMartinez/jless/commits -o commits.json $ jless commits.json $ cat commits.json | jless

jless can handle newline-delimited JSON, so feel free to pipe in the output from jq or some dense log files.

jless can also handle YAML data, either automatically by detecting the file extension, or by explicitly passing the --yaml flag. If you frequently view YAML data, we suggest the following alias:

$ alias yless="jless --yaml"

Commands

jless has a large suite of vim-inspired commands. Commands prefixed by count may be preceded by a number N, which will perform a command a given number of times.

Moving

Scrolling

Copying and Printing

You can copy various parts of the JSON file to your clipboard using one of the following y commands.

Alternatively, you can print out values using p. This is useful for viewing long string values all at once, or if the clipboard functionality is not working; mouse-tracking will be temporarily disabled, allowing you to use your terminal's native clipboard capabilities to select and copy the desired text.

jless supports full-text search over the input JSON.

Searching uses "smart case" by default. If the input pattern doesn't contain any capital letters, a case insensitive search will be performed. If there are any capital letters, it will be case sensitive. You can force a case-sensitive search by appending /s to your query.

A trailing slash will be removed from a pattern; to search for a pattern ending in / (or /s), just add another / to the end.

Search patterns are interpreted as mostly standard regular expressions, with one exception. Because JSON data contains many square and curly brackets ([]{}), these characters do not take on their usual meanings (specifying characters classes and repetition counts respectively) and are instead interpreted literally.

To use character classes or repetition counts, escape these characters with a backslash.

Some examples:

For exhaustive documentation of the supported regular expression syntax, check out the documentation of the underlying regex engine:.

Search Input

The search is not performed over the original input, but over a single-line pretty formatted version of the input JSON. Consider the following two ways to format an equivalent JSON blob:

{"a":1,"b":true,"c":[null,{},[],"hello"]} { "a": 1, "b": true, "c": [ null, {}, [], "hello" ] }

jless will create an internal representation formatted as follows:

{ "a": 1, "b": true, "c": [null, {}, [], "hello"] }

(No spaces inside empty objects or arrays, one space inside objects with values, no spaces inside array square brackets, no space between an object key and ':', one space after the ':', and one space after commas separating object entries and array elements.)

Searching will be performed over this internal representation so that patterns can include multiple elements without worrying about newlines or the exact input format.

When the input is newline-delimited JSON, an actual newline will separate each top-level JSON element in the internal representation.

Data Mode vs. Line Mode

jless starts in "data" mode, which displays the JSON data in a more streamlined fashion: no closing delimiters for objects or arrays, no trailing commas, no quotes around object keys that are valid identifiers in JavaScript. It also shows single-line previews of objects and arrays, and array indexes before array elements. Note that when using full-text search, object keys will still be surrounded by quotes.

By pressing m, you can switch jless to "line" mode, which displays the input as pretty printed JSON.

In line mode you can press % when focused on an open or close delimiter of an object or array to jump to its matching pair.

Line Numbers

jless supports displaying line numbers, and does so by default. The line numbers do not reflect the position of a node in the original input, but rather what line the node would appear on if the original input were pretty printed.

jless also supports relative line numbers. When this is enabled, the number displayed next to each line will indicate how many lines away it is from the currently focused line. This makes it easier to use the j and k commands with specified counts.

The appearance of line numbers can be configured via command line flags:

As well as at runtime:

  • :set number Show absolute line numbers.
  • :set nonumber Don't show absolute line numbers.
  • :set number! Toggle whether showing absolute line numbers.
  • :set relativenumber Show relative line numbers.
  • :set norelativenumber Don't show relative line numbers.
  • :set relativenumber! Toggle whether showing relative line numbers.
  • When just using relative line numbers, "0" will be displayed next to the currently focused line. When both flags are set, the absolute line number will be displayed next to the focused lines, and all other line numbers will be relative. This matches vim's behavior.