jq

jqlang/jq

Command-line JSON processor

PersonalEnterpriseDeveloper toolsCLIPermissive

At a glance

stars on GitHub
36k
contributors
259+
last commit
latest release, 5 months ago
jq-1.8.2
license
MIT

About

jq reads JSON and lets you filter, reshape and compute new JSON with a short query language, much like sed and awk do for plain text. It is a small C program with no runtime dependencies, available as a single binary for Linux, macOS and Windows, and it is often used in shell scripts, CI jobs and work with web APIs.

From the repository: “Command-line JSON processor”

What is jq used for?

jq is used to work with JSON on the command line. Common jobs: pretty-print an API response (curl ... | jq .), pick one field (.name), keep only the array items that match a condition (select), and build new objects from old ones. It can also turn JSON into CSV or tab-separated text with @csv and @tsv, print plain strings with -r, quote values safely for shell scripts with @sh, and take values from the shell with --arg. Developers and system administrators use it in scripts, CI jobs and one-off checks of API data, log files and configuration.

What are the alternatives to jq?

yq, which is in our catalog, uses a jq-like syntax but also reads and writes YAML, XML, CSV, TOML and other formats, and it can edit a file in place with -i. Its README says it does not yet support everything jq does. jc, also in our catalog, is a companion rather than a replacement: it turns the output of common commands such as dig into JSON so you can pipe it into jq. gojq (written in Go) and jaq (written in Rust) are re-implementations of jq. They are not in our catalog yet.

Can jq edit a JSON file in place?

No. jq always writes its result to standard output and never changes the input file. The request to add in-place editing has been open in the jq issue tracker since 2013. The usual way around it is to write to a temporary file and then replace the original, for example jq '.version = "2.0"' package.json > tmp.json && mv tmp.json package.json. If you edit configuration files often, yq offers a real in-place option (-i) with a similar syntax, and it also handles YAML.

What are the limits of jq?

jq does math in IEEE 754 double precision, so very large integers or long decimals can lose precision once you calculate with them. Since version 1.7 jq keeps a number exactly as written if you do not change it. By default jq parses each JSON value completely before filtering. For very large files there is a --stream mode, but the manual says it is harder to work with. jq reads only strict JSON: comments, trailing commas and YAML are not supported, and these remain open feature requests. The query language is powerful, but complex filters take time to learn and read.

Is jq free for commercial use?

Yes. jq itself is under the MIT license, so you can use it at work, ship it inside products and change it. GitHub shows the license as NOASSERTION only because the COPYING file contains more than one license: the documentation is under Creative Commons CC BY 3.0, and jq includes the decNumber library under the ICU license and David M. Gay's dtoa code under its own short notice. All of these are permissive. The project also signs its release files and publishes SHA-256 checksums.

Why it's in the catalog

The first tool to reach for when you need to read, filter or reshape JSON in a terminal or a shell script: pipe any API response into it. Choose yq instead when you also work with YAML, XML or TOML files, and a real programming language once the logic no longer fits in a short filter.

Get it

brew install jq
winget install jqlang.jq
docker run --rm -i ghcr.io/jqlang/jq:latest < package.json '.version'

Latest release: jq 1.8.2, . Its files were downloaded 8,887,977 times.

All files (29)

Windows

macOS

Linux

Other files

These files come from the project's GitHub release. DigGitHub does not check them.

jqlang.org
Preview of jq
Preview of jq at jqlang.org