2016-12-21 23:40:12 +00:00
|
|
|
# jq
|
|
|
|
|
2024-04-25 23:58:21 +01:00
|
|
|
> A JSON processor that uses a domain-specific language (DSL).
|
2024-02-24 19:42:40 +00:00
|
|
|
> More information: <https://jqlang.github.io/jq/manual/>.
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2023-10-08 11:49:07 +01:00
|
|
|
- Execute a specific expression (print a colored and formatted JSON output):
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-11-02 04:27:37 +00:00
|
|
|
`{{cat path/to/file.json}} | jq '.'`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2024-07-14 00:47:51 +01:00
|
|
|
- Execute a specific expression only using the `jq` binary (print a colored and formatted JSON output):
|
|
|
|
|
|
|
|
`jq '.' {{/path/to/file.json}}`
|
|
|
|
|
2022-05-29 04:02:22 +01:00
|
|
|
- Execute a specific script:
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-04-30 08:07:02 +01:00
|
|
|
`{{cat path/to/file.json}} | jq --from-file {{path/to/script.jq}}`
|
2016-12-21 23:40:12 +00:00
|
|
|
|
2022-05-29 04:02:22 +01:00
|
|
|
- Pass specific 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-05-29 04:02:22 +01:00
|
|
|
- Print specific 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-05-29 04:02:22 +01:00
|
|
|
- Print specific 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
|
|
|
|
2024-02-24 19:42:40 +00:00
|
|
|
- Print all array/object values:
|
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-05-29 04:02:22 +01:00
|
|
|
- Add/remove specific keys:
|
2020-07-17 18:37:49 +01:00
|
|
|
|
2022-11-02 04:27:37 +00:00
|
|
|
`{{cat path/to/file.json}} | jq '. {{+|-}} {{{"key1": "value1", "key2": "value2", ...}}}'`
|