title: Using jq to find and replace elements from Json sub collection
body: <p>I am trying to parse convert Json Task definition with new image.</p>
  
  <p>I want to change the <code>"image": "docker.org/alpha/alpha-app-newgen:12.2.3"</code> value in Json to <code>"image": "docker.org/alpha/alpha-app-newgen:12.5.0"</code> or any other version dynamically.</p>
  
  <p>below is my Json task def:</p>
  
  <pre><code>{
    "taskDefinition": {
      "family": "ing-stack",
      "volumes": [
        {
          "host": {
            "sourcePath": "/tmp/nginx/elb.conf"
          },
          "name": "volume-0"
        }
      ],
      "containerDefinitions": [
        {
          "dnsSearchDomains": [],
          "environment": [
            {
              "name": "API_SECRET",
              "value": "ING-SECRET"
            },
            {
              "name": "API_KEY",
              "value": "AVERA-CADA-VERA-KEY"
            }
          ],
          "readonlyRootFilesystem": false,
          "name": "ing-stg",
          "links": [],
          "mountPoints": [],
          "image": "docker.org/alpha/alpha-app-newgen:12.2.3",
          "privileged": false,
          "essential": true,
          "portMappings": [
            {
              "protocol": "tcp",
              "containerPort": 19000,
              "hostPort": 19000
            }
          ],
          "dockerLabels": {}
        },
        {
          "dnsSearchDomains": [],
          "environment": [
            {
              "name": "NG_PROXY",
              "value": "ing"
            }
          ],
          "readonlyRootFilesystem": false,
          "name": "web",
          "links": [
            "identity-ng"
          ],
          "mountPoints": [
            {
              "sourceVolume": "volume-0",
              "readOnly": false,
              "containerPath": "/etc/nginx/conf.d/default.conf"
            }
          ],
          "image": "docker.org/alpha/alpha-ui:6.4.7",
          "portMappings": [
            {
              "protocol": "tcp",
              "containerPort": 443,
              "hostPort": 443
            },
            {
              "protocol": "tcp",
              "containerPort": 80,
              "hostPort": 80
            }
          ],
          "memory": 512,
          "command": [
            "sh",
            "prep-run-nginx.sh"
          ],
          "dockerLabels": {}
        }
      ],
      "revision": 136
    }
  }
  </code></pre>
  
  <p>I need to get the same structure back with new value for the image.</p>
  
  <p>I tried the following
  <code>jq '. | select(.containerDefinitions[].image | contains("'$new_img_no_ver'")  ) | .image |= "my new image"'</code>, but its adding to the end of the JSON.</p>
  
  <p>Can anybody tell me how to achieve this.</p>