Format JSON Online
Paste minified, compact, or messy JSON below. The formatter validates it first, then outputs clean, indented JSON that is easy to read and diff — entirely in your browser.
When to Format JSON
API Debugging
API responses are often minified to save bandwidth. Format them to inspect nested fields and find the value you need.
Config Files
JSON configuration files (package.json, tsconfig.json, .eslintrc) should be formatted for readability and easy diffs in code review.
Documentation
Code examples and documentation need readable JSON. Formatting ensures consistent indentation across your docs.
Debugging Serialisation
When your backend serialises data and something looks wrong, formatting the output makes it easy to spot missing fields or wrong types.
Format JSON in Code
// JavaScript — 2-space indent
const pretty = JSON.stringify(obj, null, 2);
// JavaScript — tab indent
const prettyTabs = JSON.stringify(obj, null, "\t");
// Python — 2-space indent
import json
pretty = json.dumps(obj, indent=2)
# Python — sort keys alphabetically
pretty = json.dumps(obj, indent=2, sort_keys=True)
// Go
import "encoding/json"
b, _ := json.MarshalIndent(obj, "", " ")
fmt.Println(string(b))Formatting vs. Minifying
Formatting and minifying are opposite operations. Formatting expands JSON for readability. Minifying removes all unnecessary whitespace for production use. Both produce semantically identical JSON.
Formatted (72 bytes)
{
"name": "Alice",
"age": 30,
"active": true
}Minified (38 bytes)
{"name":"Alice","age":30,"active":true}Frequently Asked Questions
What is the difference between formatting and validating JSON?▾
Formatting (also called prettifying or beautifying) adds indentation and line breaks to make JSON human-readable — but it only works if the JSON is already valid. Validation checks whether the JSON is syntactically correct. The tool on this page does both: it validates first, then formats.
How do I format JSON in JavaScript?▾
Use the third argument of JSON.stringify(): JSON.stringify(obj, null, 2) produces indented JSON with 2-space indentation. Replace 2 with any integer or a string (e.g. '\t' for tabs) to control the indent style.
How do I format JSON in Python?▾
Use json.dumps(obj, indent=2). You can also use json.dumps(obj, indent=2, sort_keys=True) to sort keys alphabetically. For formatting a JSON file, load it with json.load() then write it back with json.dump(obj, file, indent=2).
What indentation size should I use for JSON?▾
For human-readable files (config files, API examples, documentation) 2 spaces is the most common convention. For files that will only ever be edited by tools (package.json, tsconfig.json), 2 spaces is standard. Tabs are sometimes used for consistency with a project's code style.
Does formatting change the meaning of my JSON?▾
No. Whitespace (spaces, tabs, newlines) outside of string values has no meaning in JSON. A formatted and a minified version of the same JSON are semantically identical and will parse to the same data structure.
Related JSON Tools
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.