I am using jq v1.5. Given the input:
{
"mine": [
"foo",
"baz"
],
"stuff": {
"foo": {
"name": "Foo"
},
"bar": {
"name": "Bar"
},
"baz": {
"name": "Baz"
},
"qux": {
"name": "Qux"
}
}
}
How do I get all the .stuff.names for .mine?
For example, desired output:
[
"Baz",
"Foo"
]
Using a simple jq
filter and no other shell processing, do it as below.
jq '[.mine[] as $in | .stuff[$in].name]'
The logic is basically index the values from .mine
and for each entry get the equivalent .name
value in .stuff
jqplay - URL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With