Reputation: 185
I have a JSON string like this:
{"field1" : "value!", "field2" : "value2")
Now I want to add a parent element like this to get it well formatted as a result:
{id: 123, result : ["field1" : "value!", "field2" : "value2"])
How Do I do that with JSON.parse or JSON.stringify ?
Upvotes: 3
Views: 2144
Reputation: 185
It was actually easier than I thought:
var obj1 = {"field1" : "value!", "field2" : "value2")
var obj2 = { "id" : 123, "result" : obj1 };
obj2 now holds both parents
Upvotes: 5