TOOL » LINUX » PACKAGE

Jq

Usage ​

Command-line JSON processor.

shell
jq OPTIONS FILTER FILE
OptionDescription
-r --raw-outputIf the filter's result is a string then it will be written directly to standard output.

It also accepts JSON contents from stdin.

Filters ​

FilterDescription
.Identity operator. Takes its input and produces it unchanged as output.
.fooObject Identifier-Index. Takes the value at the key foo from a JSON object (dictionary).
.[2]Array index. Zero-based, negative indices are allowed.
del(.foo)Removes a key and its corresponding value from an object.

Examples ​

Pretty-print a JSON.

shell
jq . file.json

Pretty-print a JSON with a key-value removed.

shell
jq 'del(.foo)' file.json

Get a value from a object inside an array.

shell
jq '.[0].version' file.json