3

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 ?

1
  • 1
    It was actually easier than I thought: var obj2 = { "result" : obj1 }; Commented Jul 10, 2016 at 19:41

1 Answer 1

5

It was actually easier than I thought:

var obj1 = {"field1" : "value!", "field2" : "value2")

var obj2 = { "id" : 123, "result" : obj1 };

obj2 now holds both parents

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.