0

I am having a parse Error at line 11 for parsing JSON script.

My JSON is as such:

{
    "Subject": "S001",
    "Topic":"T001",
    "SubTopic": "ST001",
    "Questions": [
    {
        "QuestionType": 1,
        "QuestionNumber": 1,
        "DifficultyLevel": "Hard",
        "QuestionVersion": 1,
        "Question": "<p>
                    The graph below shows the mass of four children.
                    <img src=\"Image1.png\"> </img>
                    If Hakim’s weight is 40kg, who weighs 20% less than Hakim?
                    </p>",
        "Options": [
                        {
                            "Answer": "Priscilla",
                            "Index" : "0"
                        }
                        {
                            "Answer": "Janet",
                            "Index" : "1"
                        }
                        {
                            "Answer": "Noel",
                            "Index" : "2"
                        }
                        {
                            "Answer": "Andrew",
                            "Index" : "3"
                        }
                   ],
        "CorrectAnswer": "Janet",
        "Explanation": "<p>
                    20% of 40kg 
                    20/100 x 40 = 8kg
                    40kg – 8kg = 32 kg
                    </p>"
    }
    ]
}

When I parse this at http://jsonlint.com/, it gives me an error:

Parse error on line 11:
...        "Question": "\<p\>                   The grap
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

How to solve this error? I need to have the

tag inside the string.

lakshmen
  • 28,346
  • 66
  • 178
  • 276

2 Answers2

3

JSON just doesn't like your line breaks. That and you're missing some commas between the objects in your options. This works fine:

{
    "Subject": "S001",
    "Topic": "T001",
    "SubTopic": "ST001",
    "Questions": [
        {
            "QuestionType": 1,
            "QuestionNumber": 1,
            "DifficultyLevel": "Hard",
            "QuestionVersion": 1,
            "Question": "<p>The graph below shows the mass of four children.<img src=\"Image1.png\"> </img>If Hakim’s weight is 40kg, who weighs 20% less than Hakim?</p>",
            "Options": [
                {
                    "Answer": "Priscilla",
                    "Index": "0"
                },
                {
                    "Answer": "Janet",
                    "Index": "1"
                },
                {
                    "Answer": "Noel",
                    "Index": "2"
                },
                {
                    "Answer": "Andrew",
                    "Index": "3"
                }
            ],
            "CorrectAnswer": "Janet",
            "Explanation": "<p>20% of 40kg 20/100 x 40 = 8kg40kg – 8kg = 32 kg</p>"
        }
    ]
}
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100
3

The problem is not with <p> but with line breaks. String values in JSON cannot be multi-line. See also: Multiline strings in JSON

Community
  • 1
  • 1
pkalinow
  • 1,619
  • 1
  • 17
  • 43