Complete Guide 5 min read

JSON: Complete Guide to the Universal Data Format

Everything about JSON — syntax rules, data types, parsing, validation, and practical use in APIs and web development.

json tutorialjson formatjson syntaxwhat is jsonjson guide

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. Despite its name mentioning JavaScript, JSON is language-independent and is used across Python, Java, PHP, Go, Ruby, and virtually every modern programming language.

JSON has become the universal format for API communication, configuration files, and data storage because it is simple, human-readable, and easy for machines to parse.

JSON Syntax: Five Rules

  • Data is in key-value pairs: "name": "value"
  • Data is separated by commas
  • Curly braces hold objects: { }
  • Square brackets hold arrays: [ ]
  • Keys must be double-quoted strings
  • JSON Data Types

    String: "Hello World" — must be double-quoted

    Number: 42 or 3.14 — no quotes

    Boolean: true or false — lowercase, no quotes

    Null: null — lowercase, no quotes

    Object: {"key": "value"} — curly braces with key-value pairs

    Array: [1, 2, 3] or ["a", "b", "c"] — square brackets

    A Complete JSON Example

    {

    "user": {

    "id": 12345,

    "name": "Ravi Kumar",

    "email": "ravi@example.com",

    "isActive": true,

    "score": 98.5,

    "address": null,

    "skills": ["Python", "React", "SQL"],

    "preferences": {

    "theme": "dark",

    "notifications": true

    }

    }

    }

    Parsing JSON in Different Languages

    JavaScript: const data = JSON.parse(jsonString)

    Python: import json; data = json.loads(json_string)

    Java: Requires Gson or Jackson library

    PHP: $data = json_decode($json_string)

    Common JSON Mistakes

    Single quotes instead of double quotes: {'name': 'value'} is invalid. Must be {"name": "value"}.

    Trailing commas: {"a": 1, "b": 2,} is invalid. No comma after the last item.

    Comments: JSON does not support comments. // and /* */ cause parse errors.

    Undefined values: undefined is not a JSON type. Use null instead.

    JSON vs JSON5 vs JSONC

    JSON5 and JSONC (JSON with Comments) are supersets of JSON that add comments, trailing commas, and other conveniences. Used in some config files (VS Code settings.json uses JSONC). Not valid JSON — cannot be parsed by standard JSON.parse().

    Frequently asked questions

    What is the difference between JSON and JSON5?

    JSON5 is a superset of JSON that adds support for comments, trailing commas, and single-quoted strings. It is not valid JSON and cannot be parsed by standard JSON parsers. Used in some developer config files.

    Why does JSON not allow comments?

    JSON was designed specifically as a data format, not a config format. Douglas Crockford (JSON creator) intentionally excluded comments to prevent people from using them as processing instructions. For config files that need comments, use JSONC or YAML.

    Try this tool on Lazyblink

    Put this guide into practice with our free online tool — no signup required.

    Open tool