Reputation: 3
I need to filter a JSON with a nested strucutre like below. All objects in array b where attribute x contains a "z" in the value of x should be filtered out. The rest should stay in the file.
{
"a": {
"b": [
{
"c": "1",
"x": "aaa",
},
{
"c": "2",
"x": "aza",
},
{
"c": "7",
"x": "azb",
}
]
},
"d": {
"e": [
"1"
],
"f": [
"2"
]
}
}
Expected output:
{
"a": {
"b": [
{
"c": "1",
"x": "aaa"
}
]
},
"d": {
"e": [
"1"
],
"f": [
"2"
]
}
}
Upvotes: 0
Views: 75
Reputation: 50815
use select
with contains
:
jq '.a.b|=[.[]|select(.x|contains("z")|not)]' file
Upvotes: 1