title: Replacing values in JSON with JQ and regex
body: <p>I have the following JSON where I want to change the "tag" of the "image" strings.</p>
  
  <pre><code>{
    "taskDefinition": {
      "containerDefinitions": [
        {
          "name": "php",
          "image": "xxxxxx.dkr.ecr.eu-west-1.amazonaws.com/repo/php:latest",
          "cpu": 0,
          "memory": 512
        },
        {
          "name": "nginx",
          "image": "xxxxxx.dkr.ecr.eu-west-1.amazonaws.com/repo/nginx:latest",
          "cpu": 0,
          "memory": 256
        }
      ],
      "family": "service-be"
    }
  }
  </code></pre>
  
  <p>It should become:</p>
  
  <pre><code>{
    "taskDefinition": {
      "containerDefinitions": [
        {
          "name": "php",
          "image": "xxxxxx.dkr.ecr.eu-west-1.amazonaws.com/repo/php:new",
          "cpu": 0,
          "memory": 512
        },
        {
          "name": "nginx",
          "image": "xxxxxx.dkr.ecr.eu-west-1.amazonaws.com/repo/nginx:new",
          "cpu": 0,
          "memory": 256
        }
      ],
      "family": "service-be"
    }
  }
  </code></pre>
  
  <p>Of course "latest" can be anything.</p>
  
  <p>So far I've found the following regex sub to modify the strings.</p>
  
  <pre><code>'.taskDefinition.containerDefinitions[].image | sub("(?&lt;repo&gt;.*:).*";  \(.repo)new")'
  </code></pre>
  
  <p>But I want to edit them in place and keep the whole JSON.
  So far my attempts to change the value were unsuccessful.
  I can change the image value to a fixed string but not to the substituted original value.</p>
  
  <p>I've tried several variations of this:</p>
  
  <pre><code>'.taskDefinition.containerDefinitions[].image |= . | sub("(?&lt;repo&gt;.*:).*"; "\(.repo)new")'
  </code></pre>
  
  <p>It seems like the version I can simply use (in Bitbucket pipelines) doesn't have the walk function, so I'd avoid it.</p>