As a developper, when I use the following JQ command:
.first_level."second_level"[] |= select(.fruit == "pear")
And I apply it to this JSON:
{
"first_level": {
"second_level": [
{
"fruit": "apple"
},
{
"fruit": "pear"
},
{
"fruit": "banana"
},
{
"fruit": "donuts"
}
]
}
}
Then I would like to have this output (only keep the items that have the property fruit equal to pear):
{
"first_level": {
"second_level": [
{
"fruit": "pear"
}
]
}
}
But the current value that is returned is (can also be seen in JQ Play here):
{
"first_level": {
"second_level": [
{
"fruit": "pear"
},
{
"fruit": "donuts"
}
]
}
}
--> It keeps the value with donuts and what I don't understand is that from the JQ documentation, the |= should assign the value of the selection but when running:
.first_level."second_level"[] | select(.fruit == "pear")
I've the following result:
{
"fruit": "pear"
}
--> It seems to select succesfully but the affectation doesn't behave as I expect (it adds the donuts).
Any help with this issue would be greatly appreciated. Thanks in advance! :)