jq . file.json

is what I was looking for. I didn't realize that the . is a filter and not a placeholder for the piped in content:

.

The absolute simplest (and least interesting) filter is .. This is a filter that takes its input and produces it unchanged as output.

And the man page makes it clear that the filter is a required argument.

Answer from k0pernikus on Stack Exchange
Discussions

How to pretty print a JSON inside a string with jq? - Stack Overflow
I'm writing a more complex transformation with jq, and one of the things I'd like to do is to have a pretty printed JSON inside a string. More on stackoverflow.com
🌐 stackoverflow.com
jq does not pretty print when output is not a terminal
if I do : cat file.json | jq . I get a formatted (pretty printed) version of the json contained in the file. But if I do: VAR=`cat file.json | jq .` echo $VAR then the output stored in $VAR is not ... More on github.com
🌐 github.com
2
October 1, 2020
pretty print as the default
For more advanced filters see the ...github.io/jq Some of the options include: -c compact instead of pretty-printed output; -n use `null` as the single input value; -e set the exit status code based on the output; -s read (slurp) all inputs into an array; apply filter to it; -r output raw strings, not JSON texts; -R read raw strings, not JSON texts; -C colorize JSON; -M monochrome (don't colorize JSON); -S sort keys of objects on output; --tab use tabs for indentation; --arg a v set variable $a to value ... More on github.com
🌐 github.com
3
April 10, 2020
json - How to pretty print using jq, so that multiple values are on the same line? - Stack Overflow
I know both forms are valid, and that jq has a compact/pretty print mode. But is there something in-between? I'm looking to somehow format a larger json file that has many more array values than this, so that it's easily readable and printable. More on stackoverflow.com
🌐 stackoverflow.com
🌐
jq
jqlang.org › manual
jq 1.8 Manual
By default, jq pretty-prints JSON output.
Top answer
1 of 2
4

This:

echo '{"foo": "bar"}' | jq '{other: .}' | jq -Rs '{json: .}'

produces:

{
  "json": "{\n  \"other\": {\n    \"foo\": \"bar\"\n  }\n}\n"
}

One way to remove the terminating "\n" would be to strip it:

echo '{"foo": "bar"}' | jq '{other: .}' | jq -Rs '{json: .[:-1]}'
2 of 2
4

I ended up writing a simple formatting function:

#   9 = \t
#  10 = \n
#  13 = \r
#  32 = (space)
#  34 = "
#  44 = ,
#  58 = :
#  91 = [
#  92 = \
#  93 = ]
# 123 = {
# 125 = }

def pretty:
  explode | reduce .[] as $char (
    {out: [], indent: [], string: false, escape: false};
    if .string == true then
      .out += [$char]
      | if $char == 34 and .escape == false then .string = false else . end
      | if $char == 92 and .escape == false then .escape = true else .escape = false end
    elif $char == 91 or $char == 123 then
      .indent += [32, 32] | .out += [$char, 10] + .indent
    elif $char == 93 or $char == 125 then
      .indent = .indent[2:] | .out += [10] + .indent + [$char]
    elif $char == 34 then
      .out += [$char] | .string = true
    elif $char == 58 then
      .out += [$char, 32]
    elif $char == 44 then
      .out += [$char, 10] + .indent
    elif $char == 9 or $char == 10 or $char == 13 or $char == 32 then
      .
    else
      .out += [$char]
    end
  ) | .out | implode;

It adds unnecessary empty lines inside empty objects and arrays, but it's good enough for my purpose. For example (used on its own):

jq -Rr 'include "pretty"; pretty' test.json

where the function is saved in pretty.jq and test.json file is:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"key":"string with \"quotes\" and \\"},"geometry":{"type":"Polygon","coordinates":[[[24.2578125,55.178867663281984],[22.67578125,50.958426723359935],[28.125,50.62507306341435],[30.322265625000004,53.80065082633023],[24.2578125,55.178867663281984]]]}}]}

gives:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "key": "string with \"quotes\" and \\"
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              24.2578125,
              55.178867663281984
            ],
            [
              22.67578125,
              50.958426723359935
            ],
            [
              28.125,
              50.62507306341435
            ],
            [
              30.322265625000004,
              53.80065082633023
            ],
            [
              24.2578125,
              55.178867663281984
            ]
          ]
        ]
      }
    }
  ]
}
🌐
LornaJane
lornajane.net › posts › 2024 › pretty-print-json-with-jq
Pretty-print JSON with jq | LornaJane
cat is a command to print the contents of the file to stdout. It’s a good way to get content into the start of a chain of commands. The | operator sends the output of the cat command into the next thing in the command. jq is a JSON tool, and the "." part is technically a filter – but it includes everything, so it’s more like a not-filter. The output of jq is the same JSON that we put in, but it’s pretty-printed.
🌐
GitHub
github.com › jqlang › jq › issues › 2185
jq does not pretty print when output is not a terminal · Issue #2185 · jqlang/jq
October 1, 2020 - if I do : cat file.json | jq . I get a formatted (pretty printed) version of the json contained in the file. But if I do: VAR=`cat file.json | jq .` echo $VAR then the output stored in $VAR is not pretty-printed.
Author   giannis-tsakiris-elsevier
🌐
Discoposse
discoposse.com › home › using jq to pretty print json output
Using jq to pretty print JSON output - DiscoPosse.com
November 12, 2017 - All we have to do to fix that up is to pipe the output from our cURL command to jq and we are able to see the pretty printed version of the JSON:
Find elsewhere
🌐
Baeldung
baeldung.com › home › web › guide to linux jq command for json processing
Guide to Linux jq Command for JSON Processing | Baeldung on Linux
August 31, 2025 - We echo a simple JSON string and pipe it into our jq command. Then we use the identity filter ‘.’ that takes the input and produces it unchanged as output with the caveat that by default jq pretty-prints all output.
🌐
Nick Janetakis
nickjanetakis.com › blog › pretty-print-json-in-your-terminal-with-jq-or-python
Pretty Print JSON in Your Terminal with jq or Python — Nick Janetakis
July 4, 2023 - I created a small ppjson script which is available in my dotfiles. It requires having jq installed and it will either use xclip or pbpaste depending on what OS you have. ... # Pretty print the contents of your clipboard with 2 spaces of indentation ppjson # Pretty print the content of a file ppjson data.json
🌐
GitHub
github.com › mgdm › htmlq › issues › 5
pretty print as the default · Issue #5 · mgdm/htmlq
April 10, 2020 - If you run jq with --arg foo bar, then $foo is available in the program and has the value "bar". Note that value will be treated as a string, so --arg foo 123 will bind $foo to "123". • --argjson name JSON-text: This option passes a JSON-encoded value to the jq program as a predefined variable.
Author   carnott-snap
🌐
jq
jqlang.org › tutorial
Tutorial
GitHub returns nicely formatted JSON. For servers that don't, it can be helpful to pipe the response through jq to pretty-print it.
🌐
Shapeshed
shapeshed.com › jq-json
JSON on the command line with jq | George Ornbo
September 19, 2024 - jq can pretty print this file using the . filter. This takes the entire input and sends it to standard output.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-transform-json-data-with-jq
How To Transform JSON Data with jq | DigitalOcean
September 23, 2025 - By default, jq will pretty print its output. It will automatically apply indentation, add new lines after every value, and color its output when possible. Coloring may improve readability, which can help many developers as they examine JSON data produced by other tools.
🌐
Bessarabov
ivan.bessarabov.com › blog › pretty-json-with-jq
JSON pretty print with jq
It is not visible in the text, but jq uses color to output json.
🌐
Linode
linode.com › docs › guides › using-jq-to-process-json-on-the-command-line
How to Use JQ to Process JSON on the Command Line | Linode Docs
November 5, 2021 - This operation takes a JSON file and formats it into easy-to-read output, with proper line spacing, standard indentation, and perfectly aligned braces. To prettify a JSON file, use the jq '.' command.