<p>I have an existing configMap with JSON data. The data could be anything that is allowed in JSON format - arrays, objects, strings, integers, etc.
For example:</p>
<pre><code>{
   &quot;channels&quot;: [&quot;10&quot;, &quot;20&quot;, &quot;30&quot;],
   &quot;settings&quot;: &quot;off&quot;,
   &quot;expiry&quot;: 100,
   &quot;metadata&quot;: {
      &quot;name&quot;: &quot;test&quot;,
      &quot;action&quot;: &quot;update&quot;
   } 
}
</code></pre>
<p>Now I want to update the configMap with newer data.
The catch is that I don't want to update any of the values, but just to add or remove any fields that have been added or removed in the new data.
The reason for this is that the values are defaults and might have been already updated in the configMap by other pods/services.
So for example, if the new data contains the below JSON data (expiry field removed and some values changed):</p>
<pre><code>{
   &quot;channels&quot;: [&quot;10&quot;, &quot;20&quot;, &quot;30&quot;, &quot;100&quot;, &quot;10000&quot;],
   &quot;settings&quot;: &quot;on&quot;,
   &quot;metadata&quot;: {
      &quot;name&quot;: &quot;test&quot;,
      &quot;action&quot;: &quot;delete&quot;
   } 
}
</code></pre>
<p>Then I expect the configMap to be updated to look like this:</p>
<pre><code>{
   &quot;channels&quot;: [&quot;10&quot;, &quot;20&quot;, &quot;30&quot;],
   &quot;settings&quot;: &quot;off&quot;,
   &quot;metadata&quot;: {
      &quot;name&quot;: &quot;test&quot;,
      &quot;action&quot;: &quot;update&quot;
   } 
}
</code></pre>
<p>so the values stayed as they were, but the 'expiry' field was removed.</p>
<p>I am using ansible to deploy the kubernetes resources, but I am open to other tools/scripts that could help me achieve what I need.</p>
<p>Thanks in advance</p>

<p>This is not supported by Kubernetes. As you said, the data is JSON-encoded, it's a string. ConfigMap (and Secrets) only understand strings, not nested data of any kind. That's why you have to encode it before storage. You'll need to fetch the data, decode it, make your changes, and then encode and update/patch in the API.</p>
