title: Print the namespace of the current context in Kubernetes
body: <p>I'd like to print the namespace of the current context in Kubernetes.</p>
  <p><code>oc config view -o json</code> returns the following output (shortened for readability)</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;kind&quot;: &quot;Config&quot;,
      &quot;apiVersion&quot;: &quot;v1&quot;,
      &quot;contexts&quot;: [
          {
              &quot;name&quot;: &quot;pp2-review/master-ocp-internal-company-com:443/Philippe&quot;,
              &quot;context&quot;: {
                  &quot;cluster&quot;: &quot;master-ocp-internal-company-com:443&quot;,
                  &quot;user&quot;: &quot;Philippe&quot;,
                  &quot;namespace&quot;: &quot;pp2-review&quot;
              }
          },
          {
              &quot;name&quot;: &quot;pp2-master/master-ocp-internal-company-com:443/Philippe&quot;,
              &quot;context&quot;: {
                  &quot;cluster&quot;: &quot;master-ocp-internal-company-com:443&quot;,
                  &quot;user&quot;: &quot;Philippe&quot;,
                  &quot;namespace&quot;: &quot;review&quot;
              }
          }
      ],
      &quot;current-context&quot;: &quot;pp2-review/master-ocp-internal-company-com:443/Philippe&quot;
  }
  </code></pre>
  <p>I'd like to return <code>pp2-review</code>. The namespace of the current context.</p>
  <p><code>oc config view -o &quot;jsonpath={\$.current-context}&quot;</code> returns <code>pp2-review/master-ocp-internal-company-com:443/Philippe</code>.</p>
  <p><code>oc config view -o &quot;jsonpath={.contexts[?(@.name==\&quot;pp2-review/master-ocp-internal-company-com:443/Philippe\&quot;)].context.namespace}&quot;</code> returns <code>pp2-review</code>.</p>
  <p>Combining them into <code>oc config view -o &quot;jsonpath={\$.contexts[?(@.name==\$.current-context)]}&quot;</code> returns nothing.</p>
  <p>Is there some other way besides executing the first command and putting its return value in the second?</p>