Difference between revisions of "jq json parser notes"
From thelinuxwiki
| Line 1: | Line 1: | ||
==jq manual== | ==jq manual== | ||
[https://stedolan.github.io/jq/manual/ jq Manual (development version)] | [https://stedolan.github.io/jq/manual/ jq Manual (development version)] | ||
| + | |||
| + | select | ||
| + | |||
| + | { | ||
| + | "json": { | ||
| + | "table": [ | ||
| + | { | ||
| + | "name": "foo", | ||
| + | "color": "green" | ||
| + | }, | ||
| + | { | ||
| + | "name": "bar", | ||
| + | "color": "blue" | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | } | ||
| + | |||
| + | $ '''cat json.json | jq '.json.table[] | select (.name == "foo")'''' | ||
| + | { | ||
| + | "name": "foo", | ||
| + | "color": "green" | ||
| + | } | ||
| + | |||
| + | |||
==Regular expressions== | ==Regular expressions== | ||
Revision as of 16:30, 14 June 2025
jq manual
jq Manual (development version)
select
{ "json": { "table": [ { "name": "foo", "color": "green" }, { "name": "bar", "color": "blue" } ] } }
$ cat json.json | jq '.json.table[] | select (.name == "foo")'
{
"name": "foo",
"color": "green"
}
Regular expressions
test(val), test(regex; flags)
Like match, but does not return match objects, only true or false for whether or not the regex matches the input
example:
$cat .tmp.json | jq '"HAHAHA 123" | test("hahaha.*[0-9]{3}"; "i")'
true