<p>Below is a <code>k8s</code> <code>configmap</code> configuration, I need to use the <code>kubectl patch</code> command to update it, but don't know how to do it</p>
<pre><code># kubectl get configmap myconfig -o yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: debug-config
data:
  config.json: |-
    {
        &quot;portServiceDMS&quot;: 500,
        &quot;Buggdse&quot;: {
            &quot;Enable&quot;: false
        },
        &quot;GHInterval&quot;: {
            &quot;Start&quot;: 5062,
            &quot;End&quot;: 6000
        },
        &quot;LOPFdFhd&quot;: false,
        &quot;CHF&quot;: {
            &quot;DriverName&quot;: &quot;mysql&quot;
        },
        &quot;Paralbac&quot;: {
            &quot;LoginURL&quot;: &quot;https://127.0.0.1:7788&quot;,
            &quot;Sources&quot;: [
                {
                    &quot;ServiceName&quot;: &quot;Hopyyu&quot;,
                    &quot;Status&quot;: false,
                    &quot;ServiceURL&quot;: &quot;https://127.0.0.1:9090/ft/test&quot;
                },
                {
                    &quot;SourceName&quot;: &quot;Bgudreg&quot;,
                    &quot;Status&quot;: false, # need to patch here to true
                    &quot;ServiceURL&quot;: &quot;https://127.0.0.1:9090&quot;  # need to patch here to  &quot;https://192.168.123.177:45663&quot;
                }
            ]
        }
    }

</code></pre>
<p>I searched on <code>google</code> site to find a similar way to deal with <a href="https://stackoverflow.com/questions/62578789/kubectl-patch-is-it-possible-to-add-multiple-values-to-an-array-within-a-sinlge">it</a>, but it doesn't work</p>
<p>I tried this command and it doesn't work：</p>
<pre><code>kubectl get cm myconfig -o json | jq -r '.data.&quot;config.json&quot;.Paralbac.Sources[1]={&quot;SourceName&quot;: &quot;Bgudreg&quot;, &quot;Status&quot;: true, &quot;ServiceURL&quot;: &quot;https://192.168.123.177:45663&quot;}' | kubectl apply -f -

</code></pre>
<p>I reduced the command to here：</p>
<pre><code>kubectl get cm myconfig -o json | jq -r '.data.&quot;config.json&quot; # it works (The double quotes are for escaping the dot)

kubectl get cm myconfig -o json | jq -r '.data.&quot;config.json&quot;.Paralbac # it can't work：   jq: error (at &lt;stdin&gt;:18): Cannot index string with string &quot;Paralbac&quot;


</code></pre>
<p>So, I think my current problem is in how to keep working after <code>escaped</code> symbols in <code>jq</code></p>

cydia
<p>Here's how you can update the ConfigMap in the question:</p>
<pre><code>myconfig=$(mktemp) \
  &amp;&amp; kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' \
  | jq '.Paralbac.Sources[1].Status = true' \
  | jq '.Paralbac.Sources[1].ServiceURL = &quot;https://192.168.123.177:45663&quot;' &gt; myconfig \
  &amp;&amp; kubectl create configmap debug-config --from-file=config.json=myconfig --dry-run=client -o yaml | kubectl replace -f - \
  &amp;&amp; rm myconfig
</code></pre>
<p>Now do <code>kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq</code> will show you the updated <strong>config.json</strong> in the ConfigMap.</p>
