Beginner Guide~12 min read

JSON Tutorial: Complete Beginner Guide

JSON (JavaScript Object Notation) is the most widely used data format on the web. This tutorial covers everything you need to know — from basic syntax to nested structures — with real examples you can paste directly into our JSON validator.

Section 1

What is JSON?

JSON stands for JavaScript Object Notation. It is a lightweight, text-based data interchange format that is easy for humans to read and write and easy for machines to parse and generate.

JSON was derived from JavaScript but is completely language-independent. Every major programming language — Python, Java, Go, Ruby, PHP, C#, Rust, Swift — has built-in support for parsing and generating JSON.

JSON was standardised in RFC 8259 (2017) and ECMA-404.

It replaced XML as the dominant data format for web APIs because it is simpler, less verbose, and directly maps to data structures found in every programming language.

Section 2

JSON Syntax Rules

JSON has a small, strict set of syntax rules. Violating any of them creates a JSON syntax error.

  • check_circle

    Data is in key/value pairs

    Keys must be strings in double quotes. Values can be any JSON data type.

  • check_circle

    Data is separated by commas

    Every item in an object or array must be separated by a comma — except the last one.

  • check_circle

    Curly braces hold objects

    { } define a JSON object — an unordered collection of key/value pairs.

  • check_circle

    Square brackets hold arrays

    [ ] define a JSON array — an ordered list of values.

  • check_circle

    Strings must use double quotes

    Single quotes are not allowed. All strings — keys and values — need double quotes.

  • check_circle

    No trailing commas

    Unlike JavaScript, JSON does not allow a comma after the last element.

  • check_circle

    No comments

    JSON does not support // or /* */ comments. They cause a syntax error.

Section 3

JSON Data Types

JSON supports exactly six data types. Every value in JSON must be one of these:

TypeExampleNotes
String"Hello, world!"Must use double quotes. Escape special characters with \.
Number42, 3.14, -17Integer or float. No NaN, Infinity, or hex literals.
Booleantrue, falseLowercase only. True and False are invalid.
NullnullRepresents absence of value. Lowercase only.
Object{"key": "value"}Unordered collection of key/value pairs in { }.
Array[1, 2, 3]Ordered list of values in [ ]. Can mix types.
Section 4

JSON Objects

A JSON object is an unordered set of key/value pairs, wrapped in curly braces { }. Keys are always strings in double quotes.

{
  "firstName": "Alice",
  "lastName": "Johnson",
  "age": 28,
  "isActive": true,
  "score": 98.5,
  "nickname": null
}

Each key/value pair is separated by a colon : and pairs are separated by commas. No comma after the last pair.

Section 5

JSON Arrays

A JSON array is an ordered collection of values wrapped in square brackets [ ]. Array elements can be any JSON type and can mix types.

{
  "tags": ["javascript", "api", "json"],
  "scores": [98, 87, 92, 100],
  "mixed": [1, "hello", true, null],
  "empty": []
}
Section 6

Nested JSON

JSON objects and arrays can be nested to any depth. This is how real-world API responses are structured:

{
  "user": {
    "id": 12345,
    "name": "Alice",
    "address": {
      "city": "San Francisco",
      "country": "US"
    },
    "orders": [
      { "id": "ord_001", "total": 79.99 },
      { "id": "ord_002", "total": 149.50 }
    ]
  }
}

Use our JSON viewer to explore deeply nested structures interactively.

Section 7

JSON vs JavaScript Objects

JSON looks like JavaScript but has stricter rules. These differences cause the most common JSON syntax errors:

FeatureJavaScriptJSON
String quotesSingle or double: 'hello' or "hello"Double quotes only: "hello"
Object keysCan be unquoted: {name: "Alice"}Must be quoted: {"name": "Alice"}
Trailing commasAllowed: [1, 2, 3,]Not allowed: [1, 2, 3]
CommentsAllowed: // and /* */Not allowed
undefinedValid valueNot a valid type
NaN / InfinityValid valuesNot valid — use null instead
FunctionsAllowed as valuesNot allowed
Section 8

Common JSON Errors

See the full JSON errors guide with before/after fix examples. The three most frequent errors are:

1

Trailing comma

{"name": "Alice",}{"name": "Alice"}
2

Unquoted keys

{name: "Alice"}{"name": "Alice"}
3

Single-quoted strings

{'name': 'Alice'}{"name": "Alice"}
See all 8 common JSON errors arrow_forward
Section 9

Where JSON is Used

api

REST & GraphQL APIs

Nearly every modern web API sends and receives data as JSON.

settings

Configuration Files

package.json, tsconfig.json, .eslintrc — all use JSON format.

storage

Databases

MongoDB, Elasticsearch, PostgreSQL JSONB — store documents as JSON.

send

Data Exchange

Between microservices, message queues, and event-driven systems.

phone_android

Mobile Apps

iOS and Android apps consume JSON from APIs and store JSON in local storage.

terminal

CLI Tools

npm, yarn, docker compose, and hundreds of CLI tools use JSON for config.

FAQ

JSON FAQ

What does JSON stand for?expand_more
JSON stands for JavaScript Object Notation. Despite the name, it is language-agnostic and used in Python, Java, Go, Rust, PHP, C#, and virtually every other programming language.
What is JSON used for?expand_more
JSON is used for API data interchange (REST, GraphQL), configuration files (package.json, tsconfig.json), database storage (MongoDB, PostgreSQL JSONB), and data serialization between services.
Is JSON the same as JavaScript?expand_more
No. JSON is inspired by JavaScript object literal syntax but is a stricter, separate format. JSON does not allow trailing commas, single quotes, comments, undefined, NaN, or Infinity values.
How do I validate JSON?expand_more
Paste your JSON into a JSON validator — it will parse the input and report any syntax errors with the exact line number. Our free JSON validator runs entirely in your browser with no server upload.
What is the difference between JSON and XML?expand_more
JSON is lighter, less verbose, and directly maps to programming language data structures. XML uses opening/closing tags which add significant overhead. JSON has largely replaced XML for web APIs.
JSON Tutorial – Complete Beginner Guide to JSON