public JsonObject merge ( JsonObject another ) { for ( Map . Entry < String , JsonElement > anotherEntry : another ) { JsonElement curr = this . opt ( anotherEntry . getKey ( ) ) ; if ( curr == null ) { try { this . put ( anotherEntry . getKey ( ) , anotherEntry . getValue ( ) ) ; } catch ( JsonException e ) { e . printStackTrace ( ) ; } } else if ( curr . isJsonObject ( ) && anotherEntry . getValue ( ) . isJsonObject ( ) ) { curr . asJsonObject ( ) . merge ( anotherEntry . getValue ( ) . asJsonObject ( ) ) ; } } return this ; }
Merge Json Object with another Json Object . It does not change element of another with the same name exists . However if the element is Json Object then it will go down and merge that object .