jq 'map(.foo)'
[ { foo: 1 }, { foo: 2 } ]
[1, 2]
jq '.[] | .foo'
[ { foo: 1 }, { foo: 2 } ]
1, 2
jq '.[1:2]'
[ { foo: 1 }, { foo: 2 } ]
{ foo: 2 }
jq 'map({ a, b })'
[ { a: 1, b: 2, c: 3 }, ...]
[ { a: 1, b: 2 }, ...]
jq 'with_entries(.value |= fromjson)' --sort-keys
{ b: "{}", a: "{}" }
{ a: {}, b: {} }
jq 'with_entries(.value |= tojson)' --sort-keys
{ a: {}, b: {} }
{ a: "{}", b: "{}" }
jq 'flatten(1)'
[[1], [2]]
[1, 2]
jq '.[] | [.foo, .bar] | @csv' -r
[{ "foo": 1, "bar": 2, "baz":3 }]
1,2
jq 'sort'
[3, 2, 1]
[1, 2, 3]
jq unique
[1, 1, 2, 1]
[1, 2]
jq --slurp '. | sort | .[]'
jq -r '(map(keys) | add | unique | sort) as $cols | .[] as $row | $cols | map($row[.]) | @csv'
[ { "foo": 1, "bar": 2}, { "foo": 3, "baz": 4}]
2,,1
,4,3
jq -rc '.[]'
Suitable for stream. See record stream
Adapted from SO (http://bit.ly/2fOwzRR)