<p>Below is my output of <code>kubectl get deploy --all-namespaces</code>:</p>
<pre><code>{
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;items&quot;: [
        {
            &quot;apiVersion&quot;: &quot;apps/v1&quot;,
            &quot;kind&quot;: &quot;Deployment&quot;,
            &quot;metadata&quot;: {
                &quot;annotations&quot;: {
                    &quot;downscaler/uptime&quot;: &quot;Mon-Fri 07:00-23:59 Australia/Sydney&quot;,
                &quot;name&quot;: &quot;actiontest-v2.0.9&quot;,
                &quot;namespace&quot;: &quot;actiontest&quot;,
            },
            &quot;spec&quot;: {
        ......
        ......
        },
        {
            &quot;apiVersion&quot;: &quot;apps/v1&quot;,
            &quot;kind&quot;: &quot;Deployment&quot;,
            &quot;metadata&quot;: {
                &quot;annotations&quot;: {
                    &quot;downscaler/uptime&quot;: &quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;,
                &quot;name&quot;: &quot;anotherapp-v0.1.10&quot;,
                &quot;namespace&quot;: &quot;anotherapp&quot;,
            },
            &quot;spec&quot;: {
        ......
        ......
        }
}
</code></pre>
<p>I need to find the name of the deployment and its namespace if the annotation <code>&quot;downscaler/uptime&quot;</code> matches the value <code>&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;</code>. I am expecting an output like below:</p>
<pre><code>deployment_name,namespace
</code></pre>
<p>If I am running below query against a single deployment, I get the required output.</p>
<pre><code>#kubectl get deploy -n anotherapp -o jsonpath='{range .[*]}{.items[?(@.metadata.annotations.downscaler/uptime==&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;)].metadata.name}{&quot;,&quot;}{.items[?(@.metadata.annotations.downscaler/uptime==&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;)].metadata.namespace}{&quot;\n&quot;}'

anotherapp-v0.1.10,anotherapp
</code></pre>
<p>But when I run it against all namespaces, I am getting an output like below:</p>
<pre><code>#kubectl get deploy --all-namespaces -o jsonpath='{range .[*]}{.items[?(@.metadata.annotations.downscaler/uptime==&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;)].metadata.name}{&quot;,&quot;}{.items[?(@.metadata.annotations.downscaler/uptime==&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;)].metadata.namespace}{&quot;\n&quot;}'


actiontest-v2.0.9 anotherapp-v0.1.10, actiontest anotherapp
</code></pre>

Vineeth Elias
<p>This is quite short answer, however you can use this option:</p>
<pre><code>kubectl get deploy --all-namespaces -o jsonpath='{range .items[?(.metadata.annotations.downscaler/uptime==&quot;Mon-Fri 07:00-21:00 Australia/Sydney&quot;)]}{.metadata.name}{&quot;\t&quot;}{.metadata.namespace}{&quot;\n&quot;}'
</code></pre>
<p>What I changed is logic how to work with data:</p>
<p>First thing what happens is getting into <code>range</code> list of elements we need to work on, not everything. I used <a href="https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html" rel="nofollow noreferrer">filter expression - see Jsonpath notation - syntax elements</a>.</p>
<p>And once we have already filtered entities in the list, we can easily retrieve other fields we need.</p>
