Reputation: 400
JSON data as below, I want to discard when "bar"="cccc" without altering the structure.
{
"foofoo": {
"barbar": [
{
"foo": "0000",
"bar": "aaaa"
},
{
"foo": "1111",
"bar": "bbbb"
},
{
"foo": "2222",
"bar": "cccc"
}
]
}
}
something like this does the trick but it alters the JSON structure.
.foofoo.barbar[] | select(.bar !="cccc")
results in:
{
"foo": "0000",
"bar": "aaaa"
}
{
"foo": "1111",
"bar": "bbbb"
}
needed result is:
{
"foofoo": {
"barbar": [
{
"foo": "0000",
"bar": "aaaa"
}
{
"foo": "1111",
"bar": "bbbb"
}
]
}
}
Thanks!
Upvotes: 0
Views: 69
Reputation: 116740
The problem with your attempt is that you've expanded .foofoo.barbar by writing .foofoo.barbar[].
What you want instead is to reset it:
.foofoo.barbar |= map(select(.bar !="cccc"))
Upvotes: 2