I have 2 JSON strings, which contains varying nested objects. I need to merge the two strings into one string, maintaining all the hierarchies. I suspect I need some sort of recursive regular expression, but this is outside my area of expertise.
Any help is greatly appreciated.
For example:
var json1 = { "root": { "Company": {"Name":"CompanyName", "Address":"MainStreet"} } }
var json2 = { "root": {"AnotherObj": { "Property":"Value"}, "Company" : {"Phone":"604"} }
var merged = { "root" : {"Company": {"Name":"CompanyName", "Address":"MainStreet", "Phone":"604"}, "AnotherObj": {"Property":"Value"}} }
So, The fields of the company object from the second string have been appended into company fields of the first string.