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