title: Overwriting one Json config on another in Java
body: <p>I have base config file x.json which is something like</p>
  <pre><code>{
    &quot;key-i&quot;  : &quot;value-i&quot;,
    &quot;key-ii&quot; : {
      &quot;key-ii-a&quot; : &quot;value-ii-a&quot;,
      &quot;key-ii-b&quot; : {
        &quot;key-ii-b-1&quot; : &quot;value-ii-b-1&quot;,
        &quot;key-ii-b-2&quot; : &quot;value-ii-b-2&quot;
      }
    }
  }
  </code></pre>
  <p>and another env specific config file x_env.json which is something like</p>
  <pre><code>{
    &quot;key-ii&quot; : {
      &quot;key-ii-b&quot; : {
        &quot;key-ii-b-2&quot; : &quot;different-value-ii-b-2&quot;
      }
    }
  }
  </code></pre>
  <p>Now I want to overwrite only config present in x_env.json on top of x.json which should look like</p>
  <pre><code>{
    &quot;key-i&quot;  : &quot;value-i&quot;,
    &quot;key-ii&quot; : {
      &quot;key-ii-a&quot; : &quot;value-ii-a&quot;,
      &quot;key-ii-b&quot; : {
        &quot;key-ii-b-1&quot; : &quot;value-ii-b-1&quot;,
        &quot;key-ii-b-2&quot; : &quot;different-value-ii-b-2&quot;
      }
    }
  }
  </code></pre>
  <p>This is only an example and x.json can be any json and how can I generically overwrite x_env.json on x.json for any json structure in Java.</p>
  <p>I am using the gson library and following to parse</p>
  <pre><code>JsonParser.parseString(IOUtils.toString(ClassName.class.getResourceAsStream(&quot;x.json&quot;))).getAsJsonObject();
  </code></pre>