Home > Net >  Issue with correct JSON syntax
Issue with correct JSON syntax

Time:11-26

I am trying to import and parse JSON in a javascript application. But at when I try to do so, my javascript code does not run. On developer tools the error I get is Uncaught SyntaxError: Unexpected token ':' on line4 (the quiztitle line). I don't understand what the syntax error with my JSON is. Here it is below.


{
    
    "quiztitle": "Quiz on the Baltic States",

    "quizarray":[

        { "questionblock1" :

        {
            "question":"What is the largest city in the Baltic States? ",
            "answer1": "Riga",
            "answer2": "Tallinn",
            "answer3": "Vilnius",
            "answer4": "Kaunas",
            "correctanswervar":"answer1",
            "correctanswer":"Riga"
        }

    }


    ]


}

CodePudding user response:

I think you JSON file is not properly formatted. I tried to reformat it for you. Please let me know if this works.

[
  {
    "quiztitle": "Quiz on the Baltic States",
    "quizarray": [
      {
        "question": "What is the largest city in the Baltic States? ",
        "answer1": "Riga",
        "answer2": "Tallinn",
        "answer3": "Vilnius",
        "answer4": "Kaunas",
        "correctanswervar": "answer1",
        "correctanswer": "Riga"
      }
    ]
  }
]

CodePudding user response:

Your JSON response is fine, there are no issues with your JSON. You can parser your JSON online here, you will not get any error http://json.parser.online.fr/

Also below I have added your JSON response as a formatted.

{
  "quiztitle": "Quiz on the Baltic States",
  "quizarray": [
    {
      "questionblock1": {
        "question": "What is the largest city in the Baltic States? ",
        "answer1": "Riga",
        "answer2": "Tallinn",
        "answer3": "Vilnius",
        "answer4": "Kaunas",
        "correctanswervar": "answer1",
        "correctanswer": "Riga"
      }
    }
  ]
}
  • Related