Reputation: 13
I've been trying to print a key and attribute value so given this JSON
[
{
"key": "foo",
"value": { "sub" : false}
},
{
"key": "bar",
"value": { "sub" : true}
}
]
I want to return something like this:
[
{
"foo": "false"
},
{
"bar": "true"
}
]
I'm using to_entries to do this but when I feed the JSON into JQ though I can't seem to access it correctly? I get an error:
jq: error (at :9): Cannot index array with string "key"
This test case simplifies the behaviour
Upvotes: 1
Views: 1431
Reputation: 134841
You can't really use to_entries
here, that creates an object out of an array of key/value objects. You're trying to map a key/value object to another object. Just map it directly.
map({ (.key): .value.sub })
Upvotes: 2