EduSupport Logo
EduSupport
JSON
Programming
Web Development

JSON Syntax Explained: How to Read and Write Valid JSON

Aug 6, 2026

5 min read

Why JSON Is Everywhere

Every time an app talks to a server — logging in, loading a feed, saving a form — data has to travel somewhere in a format both sides understand. JSON (JavaScript Object Notation) became that universal format because it is lightweight, human-readable, and native to how JavaScript already represents data. Nearly every modern API, config file, and NoSQL database speaks JSON, which is why reading and writing it correctly is a baseline skill for any CS student, not just web developers.

The Two Building Blocks

JSON has exactly two structures, and everything else is built from them.

Objects — unordered key-value pairs wrapped in curly braces:

{
  "name": "Aditi Sharma",
  "year": 2,
  "isEnrolled": true
}

Arrays — ordered lists wrapped in square brackets:

{
  "courses": ["Data Structures", "Operating Systems", "Databases"]
}

Objects and arrays nest inside each other freely — an array of objects, an object containing arrays, as deep as the data requires.

The Six Valid Data Types

JSON is strict about what a value can be. Every value must be one of exactly six types:

TypeExampleNotes
String"hello"Always double quotes — single quotes are invalid
Number42, 3.14, -7No quotes; no leading zeros; no NaN/Infinity
Booleantrue, falseLowercase, unquoted
nullnullLowercase, represents "no value"
Object{ "key": "value" }Nested key-value structure
Array[1, 2, 3]Nested ordered list

Anything outside this list — a JavaScript function, a Date object, undefined — is not valid JSON and will fail to parse.

The Syntax Rules That Trip Everyone Up

Paste a hand-written JSON blob into the JSON Formatter and it will usually fail on one of these five rules:

  1. Keys must be double-quoted strings. {name: "Aditi"} is invalid — it must be {"name": "Aditi"}.
  2. No trailing commas. ["a", "b",] fails — the comma after the last item breaks strict parsers.
  3. No comments. // this is a note is JavaScript, not JSON. There is no comment syntax in the JSON spec at all.
  4. No single quotes. {'name': 'Aditi'} is invalid JSON, even though it's valid JavaScript object syntax.
  5. Numbers can't have leading zeros or a trailing decimal point. 007 and 3. are both invalid; use 7 and 3.0.

A Complete, Valid Example

{
  "student": {
    "name": "Aditi Sharma",
    "gpa": 8.7,
    "graduated": false,
    "courses": [
      { "code": "CS201", "credits": 4 },
      { "code": "CS305", "credits": 3 }
    ],
    "advisor": null
  }
}

This single object demonstrates nesting (an object inside an object), an array of objects, every data type, and correct comma placement — no trailing comma after the last array element or the last key in each object.

JSON vs XML: Why JSON Won

Before JSON, XML was the dominant data-interchange format for APIs. The comparison explains why JSON displaced it almost everywhere except legacy enterprise systems:

JSONXML
Syntax weightMinimal — braces and colonsVerbose — opening/closing tags for everything
Native parsingBuilt into JavaScript (JSON.parse)Requires a dedicated parser library
Data typesExplicit (string, number, boolean, null)Everything is text unless schema-typed
ArraysNative [ ] syntaxNo native array — repeated tags simulate it
Human readabilityHigh, especially nested dataLower — tag overhead obscures structure

XML still has strengths (schemas, namespaces, document markup) that keep it alive in specific domains like enterprise SOAP APIs and configuration formats such as Android layouts — but for REST APIs and general data exchange, JSON's brevity won.

Debugging Malformed JSON

The most common real-world failure is a JSON string that almost parses. A missing comma, an extra brace, or a stray trailing comma anywhere in a large nested object can be genuinely hard to spot by eye. Paste the raw text into the JSON Formatter — it validates the structure, pretty-prints it with proper indentation, and points to exactly where parsing broke, entirely in your browser with nothing sent to a server.

Where JSON Shows Up in Coursework

  • API assignments — nearly every "fetch data from an API" exercise returns JSON you have to parse and traverse.
  • Config filespackage.json, tsconfig.json, and most modern tool configs are JSON.
  • NoSQL databases — MongoDB stores documents in a JSON-like format (BSON) directly.
  • Data sciencepandas.read_json() and similar functions are standard ways to load structured data.

If you're debugging an assignment where the API response, config file, or database document just won't parse — and the error message isn't telling you where — the programming help service connects you with developers who can trace the exact line breaking your JSON and explain why, not just hand you a fix.


Need one-on-one academic support?

Discuss tutoring, code review, project mentoring, or research-method guidance.

More Articles
JWT
Security
How JWT Works: JSON Web Tokens Explained Simply
5 min read
Academic Writing
Essays
Essay Word Count: How Long Should Your Essay Be?
5 min read
JSON Syntax Explained: A Beginner's Guide | EduSupport