Consider the below JSON:
[
{
"vd":[
{
"key":1
},
{
"key":2
}
]
}
]
Now I would like to filter based on the filter key==1
. So the result should be:
[
{
"vd": [
{
"key": 1
}
]
}
]
Is there a way to achieve this using jq
?
CodePudding user response:
Traverse to the array in question .[].vd
, and update |=
with a map
based on a select
using your criteria .key == 1
:
jq '.[].vd |= map(select(.key == 1))'
[
{
"vd": [
{
"key": 1
}
]
}
]