<p>In my values.yaml file for helm, I am trying to create a value with quotes but when I run it, it gives a different result</p>

<p><strong>values.yaml</strong></p>

<pre><code>annotation: '"ports": {"88":"sandbox-backendconfig"}}'

{{ .Values.annotation }}
</code></pre>

<p>what shows when I do dry run</p>

<pre><code>"ports": {"88":"sandbox-backendconfig"}}
</code></pre>

<p>how can I make the single quotes around it show also</p>

King
<p>When the Helm YAML parser reads in the <code>values.yaml</code> file, it sees that the value of <code>annotation:</code> is a <a href="https://yaml.org/spec/1.2/spec.html#id2788097" rel="noreferrer">single-quoted string</a> and so it keeps the contents of the value without the outer quotes.</p>

<p>As the YAML spec suggests, you can include single quotes inside a single-quoted string by doubling the quote.  It might be more familiar to make this a <a href="https://yaml.org/spec/1.2/spec.html#id2787109" rel="noreferrer">double-quoted string</a> and use backslash escaping.  A third possibility is to make this into a <a href="https://yaml.org/spec/1.2/spec.html#id2793652" rel="noreferrer">block scalar</a>, which would put the value on a separate line, but wouldn't require any escaping at all.</p>

<pre class="lang-yaml prettyprint-override"><code>annotation: '''"ports": {"88":"sandbox-backendconfig"}}'''
annotation: "'\"ports\": {\"88\":\"sandbox-backendconfig\"}}'"
annotation: &gt;-
  '"ports": {"88":"sandbox-backendconfig"}}'
</code></pre>

<p>I'm not sure what context you're trying to use this in, but if this is a more structured format, you can use Helm's <code>toYaml</code> or <code>toJson</code> functions to build up the annotation value for you.</p>

<pre class="lang-yaml prettyprint-override"><code># values.yaml
ports:
  '88': sandbox-backendconfig
</code></pre>

<pre class="lang-yaml prettyprint-override"><code># templates/some-resource.yaml
annotations: {{ printf "\"ports\": %s" (toJson .Values.ports) | squote }}
</code></pre>
