I'm trying to find out how to use jq to remove a certain value that occurs anywhere in the schema in an array.
In this case i'm trying to remove agent4 from anywhere inside an array underneath the field labelled agents.
This is what I have so far
jq '..|.agents? | select(. != null) | map(select(. != "agent4"))'
But that just creates the changed data and I don't know how to re-assign it to the path.
I originally tried using sed for this but its definitely not the tool to use so I switched to jq.
{
"environments": {
"default": {
"machines": {
"dev-machine": {
"agents": [
"agent1",
"agent2",
"agent3",
"agent4"
]
}
}
}
},
"environments2": {
"agents": [
"agent1",
"agent2",
"agent3",
"agent4"
]
}
}
However this just outputs
[
"agent1",
"agent2",
"agent3"
]
[
"agent1",
"agent2",
"agent3"
]