<p>I want to change <code>namespace</code> in <code>alok-pod.json</code> in the below json using jsonnet.</p>

<pre><code>{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "v1",
            "data": {
                "alok-pod.json": "{\n  \"namespace\": \"alok\",\n  \"editable\": true,\n}"
            }
        },
    ]
}
</code></pre>

<p>Please suggest how this can be done using jsonnet?</p>

<p>NOTE you'll need a <code>jsonnet</code> binary built from master, as <code>std.parseJson()</code> is not yet released as of 2019-02-26.</p>

<blockquote>
  <p><strong>input.json</strong></p>
</blockquote>

<pre><code>{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "v1",
            "data": {
                "alok-pod.json": "{\n  \"namespace\": \"alok\",\n  \"editable\": true\n}"
            }
        },
    ]
}
</code></pre>

<blockquote>
  <p><strong>edit_ns.jsonnet</strong></p>
</blockquote>

<pre><code>// edit_ns.jsonnet for https://stackoverflow.com/questions/54880959/make-changes-to-json-string-using-jsonnet
//
// NOTE: as of 2019-02-26 std.parseJson() is unreleased, 
// need to build jsonnet from master.

local input = import "input.json";

local edit_ns_json(json, ns) = (
  std.manifestJson(std.parseJson(json) { namespace: ns })
);

local edit_ns(x, ns) = (
  x {
    local d = super.data,
    data+: {
      [key]: edit_ns_json(d[key], ns) for key in std.objectFields(d)
    }
  }
);

[edit_ns(x, "foo") for x in input.items]
</code></pre>

<blockquote>
  <p>Example run:</p>
</blockquote>

<pre><code>$ jsonnet-dev edit_ns.jsonnet
[
   {
      "apiVersion": "v1",
      "data": {
         "alok-pod.json": "{\n    \"editable\": true,\n    \"namespace\": \"foo\"\n}"
      }
   }
]
</code></pre>
