How to append JSON object [duplicate]

This question already has an answer here: Concatenate two JSON objects 13 answers I have data in localStorage set with user details like this {“name”:”aa”,”email”:”aa@aa.aa”,”password”:”aaaa”,”confirm_password”:”aaaa”} and another one like {“otp”:”1235″} Now, I want to retrieve this as an single object like this {“name”:”aa”,”email”:”aa@aa.aa”,”password”:”aaaa”,”confirm_password”:”aaaa”,”otp”:”1235″} Please help. Thanks.

jsonBuilder without indexes

I tried the example described here: http://docs.groovy-lang.org/2.4.7/html/gapi/groovy/json/JsonBuilder.html this works great but how can I generate a json payload where some items do not have indexes such as “firstElt” and “secondElt” in this : [[“firstElt”,”secondElt”,[{“thirdElt”:{“id”:”1″,”name”:”laloune”},”def”:”blabla”}]]] I tried the following: import groovy.json.JsonBuilder; def builder = new groovy.json.JsonBuilder() def root = builder { ‘root’ ‘firstElt’, ‘secondElt’, thirdElt( id:…