0

I want to add elements to JSON object.

{"email":"[email protected]",
 "password":"utheu",
 "meta":
       {
         "screen_resolution":
                         {
                          "height":1080,
                          "width":1920
                         }

Above are the parameters. I want to add email, password and meta elements to JSON Object. I was able to add email and password but cannot successfully add the meta element.

2 Answers 2

1

It looks as if you forgot a couple of closing curlies

{"email":"[email protected]", 
 "password":"utheu",
 "meta":{"screen_resolution":
           {"height":1080,"width":1920}
         }
 }

is valid JSON, you can browse it here by copy/pasting it in!

Agreeing with Marc B, modifying a JSON string directly is risky!

Good luck!

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

Comments

1

What language are you doing this in? It's very bad practice to directly modify a JSON string - it's far too easy to break the entire structure and corrupt it.

You're better off decoding the JSON to your programming language's native structures, doing the manipulations using native operations, then re-encoding to JSON. It's a bit of a round trip, but far more reliable.

1 Comment

Agreed. But the reason this is an invalid JSON object is you are missing a couple closing braces at the end of the object. You close the "screen_resolution" property, but not the "meta" object. And then you need another closing brace to close the entire object: {"email":"[email protected]","password":"utheu","meta":{"screen_resolution":{"height":1080,"width":1920}}}

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.