2016-12-21 23:40:12 +00:00
|
|
|
# jq
|
|
|
|
|
2020-02-17 23:07:44 +00:00
|
|
|
> A command-line JSON processor that uses a domain-specific language.
|
2022-04-13 02:45:18 +01:00
|
|
|
> More information: <https://stedolan.github.io/jq/manual/>.
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Execute the specified expression (print a colored and formatted json):
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq '{{.}}'`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Execute the specified script:
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq --from-file {{path/to/script.jq}}'`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Pass the specifed arguments:
|
2022-03-12 04:08:08 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq {{--arg "name1" "value1" --arg "name2" "value2" ...}} '{{. + $ARGS.named}}'`
|
2022-03-12 04:08:08 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Print the specifed keys:
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq '{{.key1, .key2, ...}}'`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Print the specifed array items:
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq '{{.[index1], .[index2], ...}}'`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Print all array items/object keys:
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq '.[]'`
|
2019-04-17 15:55:23 +01:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
- Add/remove the specified keys:
|
2020-07-17 18:37:49 +01:00
|
|
|
|
2022-04-13 02:45:18 +01:00
|
|
|
`{{cat path/to/file.json}} | jq '{{.}} {{+|-}} {{{"key1": "value1", "key2": "value2", ...}}}'`
|