remove key pair from json
Hi all,
my json string = '[{"id":0,"request":1,"order":2,"q":"xyz","a":[{"text":"xyz","score":2},{"text":"Ms.","score":3},{"text":"xyz1","score":1},{"text":"Ms1","score":0}]},{"id":1,"request":0,"order":1,"q":"xyzd","a":[{"text":"xyz2","score":1},{"text":"Ms2.","score":2},{"text":"xxx2","score":0},{"text":"yyy2","score":3}]}]'
i want to remove ojbject key = "a" , "id" and its value
My current code:
var str= JSON.stringify(string)
var results= JSON.parse(str);
var name = results[0].a
name+" "
but output = undefined.
Please help
Thank you in advance
Note: above json is valid (screenshot)
-
Thank you. It worked for normal json.
How can i remove key For nested json, like remove answers:
Thank you
var quizContent = [ { "question": "Why is the sky blue?", "answers": [ { "answer": "Blue light is scattered in all directions by the tiny molecules of air in Earth's atmosphere." }, { "answer": "Idk dude" }, { "answer": "google.com" }, { "answer": "It just is." } ] }, { "question": "Why did the chicken cross the road?", "answers": [ { "answer": "To get to the other side." }, { "answer": "Obama amiriteeee" }, { "answer": "To escape genocide. "}, { "answer": "To find itself." } ] } ]
Please sign in to leave a comment.
Comments
3 comments