<p>Here is my values.yaml file:</p>

<pre><code>options:
  collection: "myCollection"
  ttl: 100800
  autoReconnect: true
  reconnectTries: 3
  reconnectInterval: 5
</code></pre>

<p>Now I'm trying to convert it into JSON in my configMap like this:</p>

<pre><code>options: {
  {{- range $key, $val := .Values.options }}
  {{ $key }}: {{ $val | quote }},
  {{- end }}
}
</code></pre>

<p>But I need to eliminate last comma in JSON so I'm trying to add a counter:</p>

<pre><code>options: {
  {{ $c := 0 | int }}
  {{- range $key, $val := .Values.options }}
  {{ if ne $c 0 }},{{ end }}
  {{- $key }}: {{ $val | quote }}
  {{ $c := $c add 1 }}
  {{- end }}
}
</code></pre>

<p>But I'm getting following error for helm template ... command:</p>

<pre><code>at &lt;$c&gt;: can't give argument to non-function $c
</code></pre>

<p>So what am I doing wrong?</p>

<p>The simplest way to increment the counter in your case would be to replace</p>
<pre><code>{{ $c := $c add 1 }}
</code></pre>
<p>with</p>
<pre><code>{{ $c = add1 $c }}
</code></pre>
