<p>I want to generate complex JSON with HELM template</p>

<p>I have a template:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  config.json: |
  {
    "test": "{{ $Value }}",
    "services": {
      {{- range $k, $v := $.Values.services }}
      "{{ $k | upper }}_PATH": "{{ $k }}",
      {{- end }}
     }
  }
</code></pre>

<p>Helm chars generates json: </p>

<pre><code>{
  "test": "test",
  "services": {
     "S1_PATH": "/t1",
     "S2_PATH": "/t2",
     "S2_PATH": "/t3",
   }
}
</code></pre>

<p>Problem is that JSON is not valid as it has a <strong>trailing comma</strong>. How to update the template to resolve this?</p>

Mindaugas Jaraminas
<p>If you update the template like this, it should work.</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  config.json: |
  {
    "test": "{{ $Value }}",
    "services": {
      {{- range $k, $v := $.Values.services }}
      {{ if ne $k 0 }},{{ end }}
      "{{ $k | upper }}_PATH": "{{ $k }}"
      {{- end }}
     }
  }
</code></pre>

<p>For the first service (index is 0) it does not place a comma and for all others it places one in front.</p>
