Given then following JSON
[
{
"id": "1",
"name": "sausage",
"value": 100
},
{
"id": "2",
"name": "spam",
"value": 200
},
{
"id": "3",
"name": "eggs",
"value": 300
}
]
I can select a single record with id=3
with:
jq '.[] | select(.id=="3") | .name,.value' data.json
### > "sausage"
### > "100"
But how to select several id
's, i.e. the items with id in (1,2)
?
## this is something I wish I could do
jq '.[] | select(.id in ("1", "2") | .name,.value' data.json
I tried:
jq '.[] | select(.id=="1") or select(.id=="2") | .name,.value' data.json
but this results in an error.
Try this:
.[] | select(.id == "3" or .id == "2") | .name,.value
Demo
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