Back to Blog

How to Format and Validate JSON

2026-05-154 min read

JSON (JavaScript Object Notation) is the dominant format for API responses, configuration files, and data exchange. It is human-readable and easy to parse, but a single misplaced comma or missing quote brings everything to a halt.

JSON Structure Basics

JSON is built from two primitives: objects (key-value pairs) and arrays (ordered lists). Keys must always be double-quoted strings. Values can be strings, numbers, booleans (true/false), null, nested objects, or arrays.

{
  "name": "Alice",
  "age": 30,
  "active": true,
  "scores": [95, 87, 92],
  "address": {
    "city": "Madrid",
    "zip": "28001"
  }
}

Common JSON Syntax Errors

  • Trailing comma: a comma after the last item in an object or array is not allowed in JSON (unlike JavaScript).
  • Single quotes: JSON requires double quotes for both keys and string values. Single quotes cause a parse error.
  • Unquoted keys: every key must be a quoted string — bare identifiers like { name: "Alice" } are not valid JSON.
  • Missing comma: forgetting the comma between two items is the most common copy-paste mistake.
  • Comments: JSON does not support comments. If you need them, use JSON5 or store comments in a separate key.

How to Format JSON Online

  1. Open the JSON Formatter tool.
  2. Paste your raw or minified JSON into the input area.
  3. Click Format to apply readable indentation.
  4. Any syntax error will be shown — fix it, then format again.
  5. Copy the formatted output or click Minify to produce a compact single-line version.

Tip: Two-space indentation is the most common convention and keeps files compact. Four-space indentation is more readable for deeply nested structures.

When to Minify JSON

Minified JSON strips all whitespace and newlines, reducing payload size. Use minified JSON in production API responses and configuration files deployed to servers. Always keep the formatted version in your source repository for readability.

JSON vs. YAML vs. CSV

  • JSON: best for API responses and nested data. Universally supported across languages and frameworks.
  • YAML: human-friendly, used in configuration files (Docker Compose, GitHub Actions, Kubernetes). Indentation-sensitive.
  • CSV: ideal for flat tabular data — spreadsheets, database exports, and simple lists.

Related Tools

Json Formatter
How to Format and Validate JSON | Utilikits Blog | Utilikits