How do I format messy JSON so humans can read it?
Raw API responses look like a cat fell asleep on your keyboard while holding down the curly bracket key. Cleaning it up takes one second.
The short answer
In JavaScript or your browser console, pass your data to JSON.stringify(data, null, 2). Or paste it into the free formatter on this site, which runs entirely in your browser.
Step 1: Paste raw JSON into a validator
Look for syntax errors such as missing quotes around keys, unescaped double quotes inside strings, or trailing commas.
Step 2: Choose 2-space or 4-space indentation
2 spaces is standard across modern web stacks and keeps deeply nested trees readable on smaller screens.
Step 3: Remove trailing commas
Unlike modern JavaScript objects, strict JSON syntax forbids trailing commas after the final key in an object or array.
ad space, reserved
Common mistakes
- Using single quotes instead of double quotes. Strict JSON requires double quotes around all keys and strings.
- Leaving a trailing comma after the last item in a list or object.
- Pasting credentials or customer data into an online formatter that sends what you paste to a server. Check whether the tool still works with the network off.