JQ: Difference between revisions
From DWIKI
mNo edit summary Tag: wikieditor |
m →FAQ Tag: wikieditor |
||
| (One intermediate revision by the same user not shown) | |||
| Line 12: | Line 12: | ||
=Examples= | =Examples= | ||
==Get the keys form key/value pairs== | |||
jq '.[] | to_entries[] .key' | |||
==get value of just one field, by name== | ==get value of just one field, by name== | ||
jq '.[].fieldname' | jq '.[].fieldname' | ||
| Line 26: | Line 30: | ||
In case of python outpout try | In case of python outpout try | ||
print(json.dumps(yourjson)) | print(json.dumps(yourjson)) | ||
===jq: parse error: Objects must consist of key:value pairs=== | |||
I got that when i tried | |||
[{ | |||
{ "name":"foo","value":"bar"} | |||
}] | |||
use | |||
[ | |||
] | |||
instead | |||
Latest revision as of 12:19, 14 April 2026
JSON processor
Links
- https://devdocs.io/jq/
- jq cheat sheet
- https://jqlang.github.io/jq/
- some nice jq trickery
- How To Transform JSON Data with jq
Related tools
- gron
- yq
Examples
Get the keys form key/value pairs
jq '.[] | to_entries[] .key'
get value of just one field, by name
jq '.[].fieldname'
or when hyphen in name
jq '.[]."field-name"'
or just
jq '.fieldname'
FAQ
Error messages
parse error: Invalid numeric literal at line 1
In case of python outpout try
print(json.dumps(yourjson))
jq: parse error: Objects must consist of key:value pairs
I got that when i tried
[{
{ "name":"foo","value":"bar"}
}]
use
[ ]
instead
