Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
JSON.parse: unexpected character at line 1 column 2 of the JSON data

I'm trying to make a quiz with HTML, CSS and JavaScript. Now i'm trying to see if the jsonData works but i get this error message but i can't find where the unecpected character is (it says line 1 column 2) but don't see it Other thing am i doing it good? I just started this year with coding

var jsonData = [
    {
        "q1": {
            "question": "what is the Capital city of Australia ",
            "answers": {
                "a": "Melbourne",
                "b": "Sydney",
                "c": "Caneberra",
                "d": "Brisbane"
            },
            "correctAnswers": "c"
        }
    },
]

const me = JSON.parse(jsonData)
console.log(me.correctAnswers);  
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problems have already been pointed out in the comments by T.J Crowder and Samball, but I wanted to show you the difference between a JavaScript data structure and a JSON string that needs to be parsed so you can better understand their comments.

  • A JSON string needs to be parsed to JavaScript data structure (array, objects, values) for you to be able to work with the data stored in the file properly
  • A JavaScript object/ array etc. that you define in JavaScript is already an JavaScript data structure so no need to parse it. Please note, any valid JSON is also valid JavaScript, but not the other way round.

Here a small program to illustrate what I've just written.

// this needs to be parsed so you can access it as JS data structures
const stringData = `[
  {
      "q1": {
          "question": "what is the Capital city of Australia ",
          "answers": {
              "a": "Melbourne",
              "b": "Sydney",
              "c": "Caneberra",
              "d": "Brisbane"
          },
          "correctAnswers": "c"
      }
  }
]`;
// no need for this to be parsed, as it already is a JS data strucure (an array in this case)
const alreadyJavaScript = [
  {
      "q1": {
          "question": "what is the Capital city of Australia ",
          "answers": {
              "a": "Melbourne",
              "b": "Sydney",
              "c": "Caneberra",
              "d": "Brisbane"
          },
          "correctAnswers": "c"
      }
  }, // In JavaScript this comma is fine, in JSON it is not!
]

// parse string
const me = JSON.parse(stringData)

// now print both to see that they are in fact identical
// Keep in mind it's an array not an object!
console.log(me[0]); 
console.log(alreadyJavaScript[0])

Note: While it is perfectly fine to put a , at the end of the last element in JavaScript, JSON does not allow that!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!