title: Add a new element to a JSON array using jq
body: <p>I have a json as mentioned in the first section and i want to add an element(&quot;image&quot;: &quot;&lt;IMAGE1_NAME&gt;&quot;,) in the json as specified in the expected output.</p>
  <p>I tired to use jq like this:</p>
  <pre><code>'.containerDefinitions += {&quot;operation&quot;:&quot;delete&quot;}'
  </code></pre>
  <p>but this seem to not work. can anyone help me the jq command to achieve the result i want.</p>
  <pre><code>{
  &quot;taskDefinitionArn&quot;: &quot;arn:aws&quot;,
  &quot;containerDefinitions&quot;: [
      {
          &quot;name&quot;: &quot;dev-service&quot;,
          &quot;cpu&quot;: 0,
          &quot;portMappings&quot;: [
              {
                  &quot;containerPort&quot;: 8080,
                  &quot;hostPort&quot;: 8080,
                  &quot;protocol&quot;: &quot;tcp&quot;
              }
          ],
          &quot;essential&quot;: true,
          &quot;environment&quot;: [
              {
                  &quot;name&quot;: &quot;message&quot;,
                  &quot;value&quot;: &quot;Hi, EMC!!&quot;
              }
          ]
          }
      }
  ]
  </code></pre>
  <p>}</p>
  <p>expected output :</p>
  <pre><code>{
  &quot;taskDefinitionArn&quot;: &quot;arn:aws:ecs:us-west-2:619867110810:task-definition/emc-dev-backend:30&quot;,
  &quot;containerDefinitions&quot;: [
      {
          &quot;name&quot;: &quot;dev-service&quot;,
          &quot;image&quot;: &quot;&lt;IMAGE1_NAME&gt;&quot;,
          &quot;cpu&quot;: 0,
          &quot;portMappings&quot;: [
              {
                  &quot;containerPort&quot;: 8080,
                  &quot;hostPort&quot;: 8080,
                  &quot;protocol&quot;: &quot;tcp&quot;
              }
          ],
          &quot;essential&quot;: true,
          &quot;environment&quot;: [
              {
                  &quot;name&quot;: &quot;message&quot;,
                  &quot;value&quot;: &quot;Hi, EMC!!&quot;
              }
          ]
          }
      }
  ]
  </code></pre>
  <p>}</p>