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

shell - Can I use jq to prettify a file in place? - Unix & Linux Stack Exchange
This order of operations also retains the original file's metadata. Since each step depends on the successful completion of the previous step (due to &&), you will not lose the document if, for example, jq fails to run. More on unix.stackexchange.com
🌐 unix.stackexchange.com
October 21, 2022
bash - How to format a JSON string as a table using jq? - Stack Overflow
I think I want to get these values ... do the formatting...? The things I tried give me varying results, but never what I really want. ... Could you add some sample output of your jq -r ... command? ... Your use of echo can be avoided jq -r '...' <<<$data or jr -r '...' < input-file.js... More on stackoverflow.com
🌐 stackoverflow.com
Create jqfmt to format jq scripts
I've written an appreciably long jq template that I'm rationally storing in a file in invoking with jq --from-file script.jq. Frustratingly, I had to format it myself by hand in order to un... More on github.com
🌐 github.com
5
November 4, 2021
bash - jq: using type in the format file - Stack Overflow
Can someone help me with the syntax of the format file with IF Statement please? ... What's with all the extra quotes? '.' or '.[2]' are wrong -- it's just ., or .[2]. Same issue throughout your code. ... Likewise, no quotes around the if block as a whole either. ... Thanks Charles for the comments. I have changed the jq ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/neovim › format json using jq
r/neovim on Reddit: Format json using jq
July 6, 2022 -

Hey all,

I have this mapping, which worked for a long time, and recently stopped working for me:

nnoremap <leader>=j :%!jq --tab .<cr>:%s/\r<cr>

This sends my file to jq, uses tabs for indent and formats the file, and then I remove `\r` throughout the file.

The problem I'm now having is I get the following error when it's run:

:%!jq --tab .
shell returned 1

:%s/\r/e

When I press enter, I get the shell error:

Start-Process: A positional parameter cannot be found that accepts argument '.'.e

I run Neovim 0.7.2, in Windows. I've set my Neovim shell to be PowerShell.

This used to work, and I've just verified that this workes in Neovim 0.7.0.

Does anyone know of anything that changed that I need to take into account in my mapping? Or do you think that they somehow broke something in 0.7.2?

Cheers,

🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-transform-json-data-with-jq
How To Transform JSON Data with jq | DigitalOcean
September 23, 2025 - In this comprehensive article, you will use jq to transform a sample JSON file about ocean animals, then progress to advanced techniques including AI integration, performance optimization, and real-world production scenarios. You’ll apply data transformations using filters, merge pieces of transformed data into new data structures, and learn how to integrate jq into modern AI and DevOps workflows.
🌐
LornaJane
lornajane.net › posts › 2024 › pretty-print-json-with-jq
Pretty-print JSON with jq | LornaJane
Wrangling some document conversion ... format. Luckily, this problem is very easily fixable …. when you know how. So today’s post is a quick recap on how I did that using jq, a very handy command-line tool for working with JSON. For the impatient, here’s the command: ... In this post we’ll look at the data I started with and what the different bits of the command to do help. My data looked like this (actually I was working with an OpenAPI file, which was ...
🌐
Codegoalie
codegoalie.com › posts › format-json-nvim-jq
Format JSON in Nvim with jq · CodeGoalie
February 12, 2024 - I often get large JSON files which contain no newlines or indentation. I’d like to look at these reasonably in neovim, but it’s been cumbersome until today. TL;DR: You can replace the contents of the buffer with output formatted by jq with one command: :%!jq .
🌐
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.
Find elsewhere
🌐
Programming Historian
programminghistorian.org › en › lessons › json-and-jq
Reshaping JSON with jq | Programming Historian
May 24, 2016 - To format this as CSV, add the operator @csv on the end with another pipe and check the “Raw Output” box in the upper right. @csv properly joins the arrays with , and adds quotes where needed. “Raw Output” tells jq that we want to produce a text file, rather than a new JSON file.
🌐
jq
jqlang.org
jq
jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you'd expect.
🌐
GitHub
github.com › wbolster › emacs-jq-format
GitHub - wbolster/emacs-jq-format: Emacs JSON reformatting using jq · GitHub
This Emacs package provides a reformatter for json and jsonlines files using the jq utility. Make sure jq is installed on your sytem. ... This package deliberately has minimal configuration. Use M-x customize-group RET jq-format or change these variables in your init.el:
Starred by 16 users
Forked by 2 users
Languages   Emacs Lisp
Top answer
1 of 10
208

Using the @tsv filter has much to recommend it, mainly because it handles numerous "edge cases" in a standard way:

.[] | [.id, .name] | @tsv

Adding the headers can be done like so:

jq -r '["ID","NAME"], ["--","------"], (.[] | [.id, .name]) | @tsv'

The result:

ID  NAME
--  ------
12  George
18  Jack
19  Joe

As pointed out by @Tobia, you might want to format the table for viewing by using column to post-process the result produced by jq. If you are using a bash-like shell then column -ts $'\t' should be quite portable.

length*"-"

To automate the production of the line of dashes:

jq -r '(["ID","NAME"] | (., map(length*"-"))), (.[] | [.id, .name]) | @tsv'
2 of 10
118

Why not something like:

echo '[{
    "name": "George",
    "id": 12,
    "email": "[email protected]"
}, {
    "name": "Jack",
    "id": 18,
    "email": "[email protected]"
}, {
    "name": "Joe",
    "id": 19,
    "email": "[email protected]"
}]' | jq -r '.[] | "\(.id)\t\(.name)"'

Output

12  George
18  Jack
19  Joe

Edit 1 : For fine grained formatting use tools like awk

 echo '[{
    "name": "George",
    "id": 12,
    "email": "[email protected]"
}, {
    "name": "Jack",
    "id": 18,
    "email": "[email protected]"
}, {
    "name": "Joe",
    "id": 19,
    "email": "[email protected]"
}]' | jq -r '.[] | [.id, .name] | @csv' | awk -v FS="," 'BEGIN{print "ID\tName";print "============"}{printf "%s\t%s%s",$1,$2,ORS}'
ID  Name
============
12  "George"
18  "Jack"
19  "Joe"

Edit 2 : In reply to

There's no way I can get a variable containing an array straight from jq?

Why not?

A bit involved example( in fact modified from yours ) where email is changed to an array demonstrates this

echo '[{
    "name": "George",
    "id": 20,
    "email": [ "[email protected]" , "[email protected]" ]
}, {
    "name": "Jack",
    "id": 18,
    "email": [ "[email protected]" , "[email protected]" ]
}, {
    "name": "Joe",
    "id": 19,
    "email": [ "[email protected]" ]
}]' | jq -r '.[] | .email'

Output

[
  "[email protected]",
  "[email protected]"
]
[
  "[email protected]",
  "[email protected]"
]
[
  "[email protected]"
]
🌐
GitHub
github.com › jqlang › jq › issues › 2366
Create jqfmt to format jq scripts · Issue #2366 · jqlang/jq
November 4, 2021 - I've written an appreciably long jq template that I'm rationally storing in a file in invoking with jq --from-file script.jq. Frustratingly, I had to format it myself by hand in order to un...
Author   colindean
🌐
Stack Overflow
stackoverflow.com › questions › 47382724 › jq-using-type-in-the-format-file
bash - jq: using type in the format file - Stack Overflow
Can someone help me with the syntax of the format file with IF Statement please? ... What's with all the extra quotes? '.' or '.[2]' are wrong -- it's just ., or .[2]. Same issue throughout your code. ... Likewise, no quotes around the if block as a whole either. ... Thanks Charles for the comments. I have changed the jq script to the below { numbers : .numbers | if type==array then .[2] else .
🌐
Medium
medium.com › @buczynski.rafal › exploring-jq-a-guide-to-essential-techniques-and-tools-for-professionals-b9df9db490de
Exploring jq: A Guide to Essential Techniques and Tools for Professionals | by Rafał Buczyński | Medium
December 17, 2025 - This command will display the contents of data.json in a nicely formatted way. If you want to see it in a compact form, you can use: ... The -c option compacts the data, removing all unnecessary spaces and line breaks. Filtering is one of the most common operations in data processing, and jq provides a simple yet powerful syntax for it. To filter elements in a JSON array, you use square brackets and conditions. For example, consider a JSON file data.json that contains an array of objects.
🌐
Codeinthehole
til.codeinthehole.com › posts › how-to-format-json-into-a-table-with-jq-and-column
TIL How to format JSON into a table with 'jq' and 'column' — David Winterbottom
$ gh pr list --json number,title,author \ | jq -r '.[] | [ .author.login, "#" + (.number|tostring) + " " + .title] | @tsv' \ | column -t -s$'\t' codeinthehole #450 Add convention on accessing environment variables LomaxOnTheRun #449 Move info from Github wiki codeinthehole #443 Format all files with `proseWrap=always` datur #428 Refactor GraphQL versioning and deprecation Conventions Dotrar #427 Add next-page template information cloverlime #425 Add advice for creating indexes on big tables zero4994 #419 Add notes to pycharm guide
🌐
Exercism
exercism.org › tracks › jq › concepts › basics
Basics in jq on Exercism
However that's not necessary for machines: the --compact-output option removes the formatting whitespace to minimize the size of the resulting JSON. ... Read the jq program from filename instead of providing it on the command line. sed and awk both use the -f option for the same purpose.
🌐
jq
jqlang.org › manual
jq 1.8 Manual
This format may change in the future. The debug(msgs) filter is defined as (msgs | debug | empty), . thus allowing great flexibility in the content of the message, while also allowing multi-line debugging statements to be created. ... Prints its input in raw and compact mode to stderr with no additional decoration, not even a newline. Returns the name of the file whose input is currently being filtered. Note that this will not work well unless jq is running in a UTF-8 locale.