Code Literacy

Unit 6 · JavaScript in the page

JSON vs a JavaScript object: the strict rules

JSON looks like a JavaScript object but is stricter: every key and every string uses double quotes, and a comma after the last item is not allowed. Break either rule and JSON.parse fails.

The mix-up

What people often think

“Single quotes work in JSON like they do in JavaScript.”

What the tutor says

JSON only accepts double quotes, for keys and for text. Single quotes make it fail to parse.

How it works

JavaScript forgives single quotes, bare keys and trailing commas. JSON forgives none of them, because it is a data format many languages have to read the same way.

JSON does not have to be an object in curly braces. A list in square brackets is valid, and so is a single string or number.

Side by side

The mix-upJavaScript
{ name: 'Priya', orders: 3, }
Fine in JavaScript, invalid JSON.
What worksJavaScript
{ "name": "Priya", "orders": 3 }
Valid JSON.

Close cousins of this mix-up

The tutor watches for these in the same lesson.

  • “A comma after the last item is harmless.”

    JavaScript forgives a trailing comma. JSON does not, and the whole thing fails.

  • “Keys do not need quotes.”

    In JavaScript objects they are optional. In JSON every key needs double quotes.

  • “JSON always has to be an object in curly braces.”

    A list in square brackets is valid JSON too. So is a single string or number.

Practise it with a tutor watching

JSON

Turn JSON text into objects and back, and spot JSON that will not parse.

15 minutes See it Build it Break it Say it
Start the lesson

Free with an account. The first two units need no account.

© 2026 webfaCeMEdia. Code Literacy™ is a trademark of webfaCeMEdia.