remove key pair from json

Comments

3 comments

  • Rainer Grabowski

    Simply delete the key - see image

     

    0
    Comment actions Permalink
  • Admin BVOT

    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." }
        ]
      }
    ]
    0
    Comment actions Permalink
  • Rainer Grabowski

    Same way:  But because var quizContent is an array and the json is element 0 in the array you must get element 0 first

    key = "answers";
    delete quizContent[0][key];
    JSON.stringify(quizContent)
    1
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk