JSON Syntax Rules

Common JSON Errors

ErrorWrongCorrect
Single quotes{'name': 'John'}{"name": "John"}
Trailing comma{"a": 1, "b": 2,}{"a": 1, "b": 2}
Unquoted key{name: "John"}{"name": "John"}
undefined{"val": undefined}{"val": null}

JSON vs Other Formats

JSON vs XML: JSON is lighter, easier to parse, and has become the standard for web APIs. XML supports comments, attributes, and schemas but is more verbose.

JSON vs YAML: YAML is more human-readable (no brackets, uses indentation) and supports comments. Used for config files (Docker Compose, Kubernetes). JSON is better for data exchange because it's unambiguous.