<p>I'm accessing Kubernetes through the CLI tool <code>kubectl</code> and I'm trying to get a list of all context names, one per line.</p>

<p>I know that JSONPath can be used to extract and format specific output.  I get really close to what I want with</p>

<pre class="lang-sh prettyprint-override"><code>kubectl config view -o=jsonpath="{.contexts[*].name}"
</code></pre>

<p>but this puts all the names on the same line.  I'm trying to use <code>range</code> to list all names separated by newlines:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl config view -o=jsonpath='{range .contexts[*]}{.name}{"\n"}{end}'
</code></pre>

<p>But this just gives me an error:</p>

<pre><code>error: unexpected arguments: [.contexts[*]}{.name}{"\n"}{end}]
See 'kubectl config view -h' for help and examples.
</code></pre>

<p>I've reviewed the <code>kubectl</code> documentation and what I'm doing is really similar to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-containers-by-pod" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-containers-by-pod</a>, where the command is</p>

<pre><code>kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\
sort
</code></pre>

<p>but I can't see where I'm going wrong.</p>

<p>Your command works for me in kubectl 1.9.2</p>

<p>If it still doesn't work, you can use tr in bash to replace spaces with new lines:</p>

<pre><code>kubectl config view -o=jsonpath="{.contexts[*].name}" | tr " " "\n" 
</code></pre>
