Replace subkey without exact path in jq
<p>Example JSON file:</p>

<pre><code>{
  "u": "stuff",
  "x": [1,2,3],
  "y": {
    "field": "value"
  },
  "z": {
    "zz": {
       "name": "change me",
       "more": "stuff"
    },
    "randomKey":  {
       "name": "change me",
       "random": "more stuff"
    }
  }
}
</code></pre>

<p>How can I update all the name fields to "something", maintaining the rest of the JSON file the same?</p>

<pre><code>{
  "u": "stuff",
  "x": [1,2,3],
  "y": {
    "field": "value"
  },
  "z": {
    "zz": {
       "name": "something",
       "more": "stuff"
    },
    "randomKey":  {
       "name": "something",
       "random": "more stuff"
    }
  }
}
</code></pre>

<p>With a direct path, this would be easy, but the parent keys (z and randomKey in these case) varies.</p>

<p>I tried something like:</p>

<pre><code>jq '.z | .. | .name? |= "something"' file.json
</code></pre>

<p>And it's updating the names, but putting also all the recursive stuff..</p>