<p>I am trying to pass given part of values.yaml into helm template:</p>
<pre><code>  receivers:
    test1:
      test2:
        test3:
    test4: 
</code></pre>
<p>using function:</p>
<p><code>{{ .Values.receivers | toYaml | nindent 2}}</code></p>
<p>Code is placed in correct format, however empty fields get filled with 'null':</p>
<pre><code>receivers:
  test1:
    test2:
      test3: null
  test4: null
</code></pre>
<p>Is there any way to prevent this?</p>
<p>I am expecting correct templating without insterted null fields.</p>

<p>There are no fields inserted. The processor only replaces values that already exist with a different serialization that has the same semantics.</p>
<p><code>test3:</code> in YAML without a value is parsed as having an empty scalar value. The <a href="https://yaml.org/spec/1.2.2/#103-core-schema" rel="nofollow noreferrer">YAML Core Schema</a> defines the following for empty values:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Regular expression</th>
<th>Resolved to tag</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>null | Null | NULL | ~</code></td>
<td>tag:yaml.org,2002:null</td>
</tr>
<tr>
<td><em><code>/* Empty */</code></em></td>
<td>tag:yaml.org,2002:null</td>
</tr>
</tbody>
</table>
</div>
<p>Since the empty value is resolved to have the tag <code>!!null</code> (which is a shorthand for the full form shown above), it is loaded as <strong><code>nil</code></strong> into Go.</p>
<p>When <code>toYaml</code> receives your data, it doesn't know that the <strong><code>nil</code></strong> values originated from empty scalars. It needs to choose one of the possible serializations and chooses <code>null</code>. This adheres to the YAML spec and is therefore correct behavior.</p>
<p>Any downstream processor that supports the Core Schema should process <code>test3: null</code> in the same way it processes <code>test3:</code> without value. Therefore there should be no problem.</p>
<p>If you want <code>test3:</code> to specifically have the <em>empty string</em> as value instead of <code>null</code>, write</p>
<pre class="lang-yaml prettyprint-override"><code>test3: &quot;&quot;
</code></pre>
<p>If you want it to contain an empty mapping, write</p>
<pre class="lang-yaml prettyprint-override"><code>test3: {}
</code></pre>
