← All articles

JSON: what it is, syntax, validation and best practices

June 23, 2026 · Read 5 min

JSON (JavaScript Object Notation) is the most used format for data exchange between applications. If you work with APIs, configurations or structured data, you encounter it daily. This guide covers syntax, types, common errors and best practices.

JSON syntax: the basic rules

JSON is simple: it has two main structures, objects and arrays.

  • Object: collection of key-value pairs, enclosed in { }. Keys are double-quoted strings, separated from values by :, pairs separated by ,.
  • Array: ordered list of values, enclosed in [ ], separated by ,.

Example:

{"name": "John", "age": 30, "hobbies": ["football", "music"], "active": true, "address": null}

Supported data types

  • String: text in double quotes (e.g. "hello")
  • Number: integers or decimals (e.g. 42, 3.14)
  • Boolean: true or false
  • null: absence of value
  • Object: nested objects
  • Array: array of any type

Note what is NOT supported: comments, single quotes, functions, dates (must be serialized as ISO string).

Common JSON errors (and how to fix them)

  1. Trailing comma: {"a": 1,} is invalid. Remove the last comma.
  2. Unquoted keys: {a: 1} is not JSON, it's JavaScript. Use {"a": 1}.
  3. Single quotes: {'a': 1} is invalid. Use double quotes.
  4. Comments: // comment or /* ... */ are not allowed.
  5. Trailing comma in arrays: [1, 2, 3,] is invalid.

Our JSON validator tells you exactly the line and position of the error, saving you minutes of debugging.

Minify vs pretty-print

JSON over the network is sent minified (a single line, no spaces) to reduce bytes. To read it, you pretty-print it adding indentation (usually 2 or 4 spaces). Example:

{"a":1,"b":[2,3]}{ "a": 1, "b": [2, 3] }

Best practices

  • Use camelCase for keys (JSON convention).
  • Version your APIs (URL or header) to avoid breaking changes.
  • For dates use ISO 8601 (e.g. "2026-06-23T14:30:00Z").
  • Keep API responses flat when possible: deeply nested JSON is hard to consume.
  • Always validate JSON input server-side, even if it comes from yourself.
Have JSON to format or validate? Use our free JSON Formatter — pretty-print, minify, one-click copy.
ToolHub — Published by ToolHub, the collection of free web utilities.