<p><strong>Values</strong></p>
<pre><code>a :
  b:c
  d:e
  f: 
    g:h
</code></pre>
<p>I have <strong>config map</strong></p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: myName
  labels:
data:
  myDaya.cfg: |-
    {{ toJson .Values.a }} 
</code></pre>
<p><strong>The result is</strong></p>
<pre><code>myDaya.cfg: {&quot;b&quot;:&quot;c&quot;, &quot;d&quot;,&quot;e&quot;, &quot;f&quot;:{&quot;g&quot;:&quot;h&quot;}}}
</code></pre>
<p>Now I added another values to <strong>.values</strong> file</p>
<pre><code>a1:
  b1:
    c1: d1
</code></pre>
<p>The &quot;a1&quot; must be in different structure<br />
The new <strong>.Values</strong></p>
<pre><code>a :
  b:c
  c:d
  e: 
    f:g
**a1:
  b1:
    c1: d1**
</code></pre>
<p>The new config now should include 1 json also with value a1 meaning</p>
<pre><code>myDaya.cfg: {&quot;a&quot;: { &quot;b&quot;:&quot;c&quot;, &quot;d&quot;,&quot;e&quot;, &quot;f&quot;:{&quot;g&quot;:&quot;h&quot;}} ,&quot;b1:{&quot;c1&quot;:&quot;d1&quot;}}
</code></pre>
<p>Could you advise me how I can change the config map ?</p>

user1365697
<p>Helm has <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#dictionaries-and-dict-functions" rel="nofollow noreferrer">several functions for manipulating dictionary objects</a> (which come from the <a href="http://masterminds.github.io/sprig/dicts.html" rel="nofollow noreferrer">Sprig template support library</a>).  These include a <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#merge-mustmerge" rel="nofollow noreferrer"><code>merge</code></a> function that combines multiple dictionaries into one.</p>
<p>The one trick with the dictionary functions is that they generally work by mutating an existing dictionary object.  This is in contrast to most of the other Helm/Sprig functions, which act on immutable objects.  So to use <code>merge</code> without accidentally changing <code>.Values</code>, you need to create a new empty dictionary (with <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#dict" rel="nofollow noreferrer"><code>dict</code></a> and then <code>merge</code> the various sub-dictionaries into it.</p>
<pre class="lang-yaml prettyprint-override"><code>data:
  myDaya.cfg: |-
{{ merge dict .Values.a .Values.a1 | toJson | indent 4 }}
</code></pre>
<p>Or, if you want to keep the top-level dictionary keys, you can use <code>dict</code> to directly construct the result dictionary:</p>
<pre class="lang-none prettyprint-override"><code>{{ dict &quot;a&quot; .Values.a &quot;a1&quot; .Values.a1 | toJson | indent 4 }}
</code></pre>
