title: Nunjucks: Can I combine, concatenate or update a JSON object?
body: <p>Is it possible to amend, update, combine, concatenate or otherwise join 2 bits of JSON in Nunjucks?</p>
  <p>Here's an example: I'm trying to add an element to an existing variable. (The element can exist as an empty string, but I can't find a way to update that either..)</p>
  <p>Given this JSON stucture:</p>
  <pre class="lang-json prettyprint-override"><code>{
    type: &quot;radio&quot;,
    items: [
      {
        value: &quot;yes&quot;,
        text: &quot;Yes&quot;
      },
      {
        value: &quot;no&quot;,
        text: &quot;No&quot;
      }
    ]
  }
  </code></pre>
  <p>I then want to add the following <code>error</code> element so I have:</p>
  <pre class="lang-json prettyprint-override"><code>{
    type: &quot;radio&quot;,
    items: [
      {
        value: &quot;yes&quot;,
        text: &quot;Yes&quot;
      },
      {
        value: &quot;no&quot;,
        text: &quot;No&quot;
      }
    ],
    error: {
      message: &quot;Some message. This could be empty to start with and updated somehow too&quot;
    }
  }
  </code></pre>
  <p>This is the closest I've managed to get..</p>
  <pre><code>{# index.njk #}
  
  {% set question = {
    type: &quot;radio&quot;,
    items: [
      {
        value: &quot;yes&quot;,
        text: &quot;Yes&quot;
      },
      {
        value: &quot;no&quot;,
        text: &quot;No&quot;
      }
    ]
  }
  %}
  
  {{ question | dump }}
  
  &lt;hr&gt;
  
  {# now I want to add or update a value in that JSON variable.. #}
  {% set question = question + {
    error: {
      message: &quot;some error message&quot;
    }
  }
  %}
  
  {{ question | dump }}
  
  {# outputs: &quot;[object Object][object Object]&quot; #}
  {# desired output: { &quot;type&quot;: &quot;radio&quot; .... , &quot;error&quot;: &quot;some error message&quot; } #}
  
  </code></pre>