How to format JSON online
- Paste your JSON into the Input box, upload a .json file, or click Sample to try it.
- The formatted result appears instantly on the right. Choose Beautify (2 spaces, 4 spaces or tabs) or Minify.
- If the JSON is invalid, the status bar shows what’s wrong and where. Click Jump to error to select the problem character.
- Tick Sort keys to order object keys alphabetically, which makes two responses easy to compare.
- Copy the result or download it as a .json file.
Beyond formatting, the status bar counts keys and nesting depth and warns about numbers that are too large for JavaScript to keep exactly. That’s a common source of mysteriously changing IDs.
Common JSON errors and how to fix them
| Error | Invalid example | Fix |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Remove the comma before } or ]. |
| Single quotes | {'name': 'Ada'} | Use double quotes for keys and strings: {"name": "Ada"}. |
| Unquoted keys | {name: "Ada"} | Quote every key. That's JavaScript object syntax, not JSON. |
| Smart quotes | {“name”: “Ada”} | Curly quotes from Word, Slack or Notes aren't valid. Retype them as straight quotes. |
| Comments | {"a": 1 // note} | JSON has no comments. Remove them, or use JSONC/JSON5 where your tool supports it. |
| NaN, Infinity, undefined | {"score": NaN} | Not valid JSON values. Use null or a number. |
| Two top-level values | {"a":1}{"b":2} | Wrap them in an array, or treat the data as JSON Lines (one value per line). |
Pretty-print JSON in code
Need to format JSON in a script or pipeline instead? Every major language can do it in one line:
const pretty = JSON.stringify(data, null, 2); // 2-space indent
const minified = JSON.stringify(data);
// Format a raw JSON string
const formatted = JSON.stringify(JSON.parse(raw), null, 2);import json
pretty = json.dumps(data, indent=2, ensure_ascii=False)
minified = json.dumps(data, separators=(",", ":"))
sorted_keys = json.dumps(data, indent=2, sort_keys=True)# jq: format, colourise and validate
curl -s https://api.open-meteo.com/v1/forecast?latitude=6.45\&longitude=3.39\¤t=temperature_2m | jq .
# No jq? Python ships a formatter
cat data.json | python3 -m json.tool
# Minify with jq
jq -c . data.json<?php
$pretty = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$minified = json_encode($data);pretty, err := json.MarshalIndent(data, "", " ")
// Re-indent raw JSON bytes without decoding into a struct
var out bytes.Buffer
err = json.Indent(&out, raw, "", " ")Practise on real API responses
Most public APIs return minified JSON. Paste a response from one of these free APIs (none needs a key) to see its structure:
- Open-Meteo: weather forecasts, nested objects of arrays.
- PokéAPI: deep, large responses, a good test for big JSON.
- JSONPlaceholder: fake posts, users and todos for testing.
- Cat Facts: tiny, simple responses for first experiments.
- REST Countries: country data with names, currencies and flags.
Want types for that response? Use JSON to TypeScript & Zod. Browse every API that needs no key, or read what a public API is if you’re new to them.