Hi! My input looks like this:
{
"results" : [
{
"some.key" : 3
},
{
"some.key" : 4
}
]
}
I'd like to be able to do this
./jq ".results.some.key" input
But I can't. I can't figure out how to access those keys, is this possible? Also, I cannot change the schema....
Sorry, I could't find it in the documentation but I found it in a closed issue:
./jq '.results[]["some.key"]' input
Yeah, the docs are a bit weak on this point. .foo is just shorthand for .["foo"], like in JS (or lua).
I ran into this, and in case it helps anyone:
.foo is equivalent to .["foo"] (as noted above).foo.bar is equivalent to any of:.["foo"]["bar"].foo["bar"].["foo"].barSorry for the bump. What about the case where you want to interpolate a key with a dot? i.e.
$ echo '[{"foo":2},{"foo":1}]' | jq -r '.[] | "\(.foo)"'
2
1
$ echo '[{"foo.bar":2},{"foo.bar":1}]' | jq -r '.[] | "\(.what do I put here???)"'
@marianogappa For all non-ident-like keys use .["whatever the key is goes here"]. Interpolation uses jq expressions, so
$ echo '[{"foo.bar":2},{"foo.bar":1}]' | jq -r '.[] | "\(.["foo.bar"])"'
I think you can more with terraform output -json directly like this, without the need of a third party python library.
$ terraform output -json | jq -r ".quadrant.value.\"$QUAD.region\""
us-east-1
Most helpful comment
Sorry, I could't find it in the documentation but I found it in a closed issue:
./jq '.results[]["some.key"]' input