newb1001
newb1001

Reputation: 23

JSON "Expected String got undefined" error

I'm getting an error saying this:

Parse error on line 1:
{   quizzes:{    quiz_1
----^
Expecting 'STRING', '}', got 'undefined'

I followed a tutorial and it's line for line but it's still not working. Any help would be appreciated.

I'm very new to JSON and have tried everything I've seen on Google. My code doesn't contain any of the inverted quote marks.

{ 
  quizzes:{
    quiz_1: {
      "QuizName": "Addition"
    },
    quiz_2: {
      "QuizName": "Subtraction"
    },
    quiz_3: {
      "QuizName": "Dividing"
    }
  },
  questions:{
    quiz_1: {
      question_1:{ 
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      },
    },
    question_2:{
      quiz_2: {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      },
    },
    question_3:{
      quiz_3: {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    }
  }
}

Upvotes: 1

Views: 3936

Answers (1)

zedfoxus
zedfoxus

Reputation: 37059

Your JSON should look like this.

Note that quizzes is within double-quotes. Think of it as a double-quoted key.

There was a comma after question_1's object. Remove that. You can use https://jsonlint.com/ to validate that your JSON is correct.

{ 
  "quizzes":{
    "quiz_1": {
      "QuizName": "Addition"
    },
    "quiz_2": {
      "QuizName": "Subtraction"
    },
    "quiz_3": {
      "QuizName": "Dividing"
    }
  },
  "questions":{
    "quiz_1": {
      "question_1":{ 
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    },
    "question_2":{
      "quiz_2": {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    },
    "question_3":{
      "quiz_3": {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    }
  }
}

Upvotes: 1

Related Questions