<p>I have a command similar to this</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get secrets \
--selector='my-selector' \
-o jsonpath='{range .items[*] }{&quot;\n&quot;}{.metadata.labels.cluster-name}{&quot;.&quot;}{.metadata.namespace {&quot;:&quot;}{&quot;5432&quot;}{&quot;postgres&quot; }{&quot;:&quot;}{.data.password}{end}'
</code></pre>
<p>which outputs a list like this (format required)</p>
<pre><code>cluster-name.namespace:5432:postgres:YbHF....==
cluster-name.namespace:5432:postgres:YbHF....==
cluster-name.namespace:5432:postgres:YbHF....==

</code></pre>
<p>I need to decode the base64 for this file and using the <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="nofollow noreferrer">kubectl cheat sheet</a> as a reference which gives this example:</p>
<pre><code># Output decoded secrets without external tools
kubectl get secret my-secret -o go-template='{{range $k,$v := .data}}{{&quot;### &quot;}}{{$k}}{{&quot;\n&quot;}}{{$v|base64decode}}{{&quot;\n\n&quot;}}{{end}}'
</code></pre>
<p>I tried the following</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get secrets \
--selector='my-selector' \
-o jsonpath='{range .items[*] }{&quot;\n&quot;}{.metadata.labels.cluster-name}{&quot;.&quot;}{.metadata.namespace {&quot;:&quot;}{&quot;5432&quot;}{&quot;postgres&quot; }{&quot;:&quot;}{.data.password|base64decode}{end}'
</code></pre>
<p>The result is that everything appears apart from the password field which is now blank, for example:</p>
<pre><code>cluster-name.namespace:5432:postgres:
</code></pre>
<p>Any pointers would be appreciated.</p>

Alan
<p>As per @mdaniel suggestion I used the <code>-o go-template</code></p>
<p>My main syntaxal changes were removing the [ ], ie, <code>{range .items[*] }</code> to <code>{{range .items}}'</code></p>
<p>And if a key contained a <code>-</code> then <code>{.metadata.labels.cluster-name}</code> became <code>{{index .metadata.labels &quot;cluster-name&quot;}}</code></p>
<p>My solution below which enabled the base64 decode to work:</p>
<pre><code>kubectl get secrets \
--selector='my-selector' \
-o go-template='{{range .items}}{{&quot;\n&quot;}}{{index .metadata.labels &quot;cluster-name&quot;}}{{&quot;.&quot;}}{{.metadata.namespace }}{{&quot;:&quot;}}{{&quot;5432&quot;}}{{&quot;postgres&quot;}}{{&quot;:&quot;}}{{.data.password|base64decode}}{{end}}'
</code></pre>
