<p><strong>Problem:</strong></p>

<p>I want to read a json file into a configmap so it looks like:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: json-test
data:
  test.json: |-
    {
      "key": "val"
    }
</code></pre>

<p>Instead I get</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: json-test
data:
  test.json: |-
      "{\r\n    \"key\": \"val\"\r\n}"
</code></pre>

<p><strong>What I've done:</strong></p>

<p>I have the following helm chart:</p>

<pre><code>Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2020-02-06  10:51 AM                static
d-----        2020-02-06  10:55 AM                templates
-a----        2020-02-06  10:51 AM             88 Chart.yaml
</code></pre>

<p>static/ contains a single file: <code>test.json</code>:</p>

<pre><code>{
    "key": "val"
}
</code></pre>

<p>templates/ contains a single configmap that reads test.json: <code>test.yml</code>:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: json-test
data:
  test.json: |-
  {{ toJson ( .Files.Get "static/test.json" ) | indent 4}}
</code></pre>

<p>When I run <code>helm install test . --dry-run --debug</code> I get the following output</p>

<pre><code>NAME: test
LAST DEPLOYED: Thu Feb  6 10:58:18 2020
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
{}

HOOKS:
MANIFEST:
---
# Source: sandbox/templates/test.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: json-test
data:
  test.json: |-
      "{\r\n    \"key\": \"val\"\r\n}"
</code></pre>

<p>The problem here is my json is wrapped in double quotes. My process that wants to read the json is expecting actual json, not a string.</p>

Connor Graham
<p>I see that this is not specific behavior only for <strong>helm 3</strong>. It generally works in <strong>kubernetes</strong> this way.</p>

<p>I've just tested it on <strong>kubernetes v1.13</strong>.</p>

<p>First I created a <code>ConfigMap</code> based on this file:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: json-test
data:
  test.json: |-
    {   
      "key": "val"
    }
</code></pre>

<p>When I run:</p>

<pre><code>$ kubectl get configmaps json-test -o yaml
</code></pre>

<p>I get the expected output:</p>

<pre><code>apiVersion: v1
data:
  test.json: |-
    {
      "key": "val"
    }
kind: ConfigMap
metadata:
...
</code></pre>

<p>but when I created my <code>ConfigMap</code> based on json file with the following content:</p>

<pre><code>{   
      "key": "val"
} 
</code></pre>

<p>by running:</p>

<pre><code>$ kubectl create configmap json-configmap --from-file=test-json.json
</code></pre>

<p>Then when I run:</p>

<pre><code>kubectl get cm json-configmap --output yaml
</code></pre>

<p>I get:</p>

<pre><code>apiVersion: v1
data:
  test-json.json: "    {   \n      \"key\": \"val\"\n    } \n"
kind: ConfigMap
metadata:
...
</code></pre>

<p>So it looks like it's pretty normal for kubernetes to transform the original <strong>json format</strong> into <strong>string</strong> when a <code>ConfigMap</code> is created from file.</p>

<p>It doesn't seem to be a bug as kubectl doesn't have any problems with extracting properly formatted json format from such <code>ConfigMap</code>:</p>

<pre><code>kubectl get cm json-configmap -o jsonpath='{.data.test-json\.json}'
</code></pre>

<p>gives the correct output:</p>

<pre><code>{   
  "key": "val"
}
</code></pre>

<p>I would say that it is application responsibility to be able to extract <strong>json</strong> from such <strong>string</strong> and it can be done probably in many different ways e.g. making direct call to <code>kube-api</code> or using <code>serviceaccount</code> configured to use <code>kubectl</code> in <code>Pod</code>.</p>
