<p>I have data in a JSON file and am adding each line as key value into a ConfigMap using Helm, but i need to remove first and last curly brackets.</p>
<p>Below is the JSON file content:</p>
<pre><code>{
    &quot;type&quot;: &quot;PurposeResourcesDefinition&quot;,
    &quot;version&quot;: &quot;1.0&quot;,
    &quot;purposeId&quot;: &quot;p#####&quot;,
    &quot;description&quot;: &quot;Artifactory container registry&quot;,
    &quot;resources&quot;: [{
        &quot;type&quot;: &quot;artifactory.containerregistry&quot;,
        &quot;name&quot;: &quot;&lt;repository name prefixed with the purpose&gt;&quot;
    ]
}
</code></pre>
<p>I am using the below Helm syntax:</p>
<pre class="lang-yaml prettyprint-override"><code>data:
  {{ range .Files.Lines &quot;foo/app.json&quot; }}
  {{ . }}{{ end }}
</code></pre>
<p>How can I remove the surrounding curly brackets using Helm templating?</p>

ramesh reddy
<p>If you know that <code>{</code> and <code>}</code> will be on lines by themselves, you can just skip them.  This isn't especially robust, but it will work for the example you show.</p>
<pre class="lang-yaml prettyprint-override"><code>data:
{{- range .Files.Lines &quot;foo/app.json&quot; }}
{{- if and (ne . &quot;{&quot;) (ne . &quot;}&quot;) }}
  {{ . }}
{{- end }}
</code></pre>
<p>At a higher level, it looks like you're trying to read in a JSON file and then write these values out as the contents of a ConfigMap.  Stripping the leading and trailing braces will work because of the syntactic similarities between YAML and JSON, but it might be better to actively convert from one format to the other.  Helm has <a href="https://github.com/helm/helm/blob/master/pkg/engine/funcs.go#L50" rel="nofollow noreferrer">several undocumented conversion functions</a> including <code>fromJson</code> and <code>toYaml</code>.  So you can also write this as:</p>
<pre class="lang-yaml prettyprint-override"><code>data: {{- .Files.Get &quot;foo/app.json&quot; | fromJson | toYaml | nindent 2 }}
</code></pre>
