JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the JSON Formatter
API responses and config files often arrive as one long line of JSON. The JSON Formatter turns it into readable, consistently indented JSON and tells you exactly where the syntax breaks when it is invalid.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the JSON Formatter
- Paste JSON into the input panel, open a .json file, load it from a URL with From URL, or load the sample.
- Choose 2 spaces, 4 spaces or tabs for indentation, and switch on key sorting if you want a stable order.
- Fix any error using the reported line and column, then copy or download the formatted result, or switch the output to Tree to fold and explore it.
Example
Input
{"id":42,"name":"Ada","roles":["admin","dev"],"active":true}Result
{
"id": 42,
"name": "Ada",
"roles": [
"admin",
"dev"
],
"active": true
}Formatted with 2-space indentation. Switch on Sort keys to order "active", "id", "name", "roles" alphabetically.
Common mistakes
- Trailing commas. A comma after the last item, as in [1, 2, ], is valid JavaScript but invalid JSON. Remove it; the error points to the character right after it.
- Single quotes and unquoted keys. JSON requires double quotes around every key and string: {"name": "Ada"}, not {name: 'Ada'}. Objects copied from JavaScript code often break this rule.
- Comments. Standard JSON has no comments. Files such as tsconfig.json accept them (JSONC), but APIs and JSON.parse do not, so strip // and /* */ comments first.
- Very large numbers. Integers above 9,007,199,254,740,991 cannot be represented exactly in JavaScript, so 12345678901234567890 is formatted as 12345678901234567000. Send large IDs as strings.
- Duplicate keys. When a key appears twice in an object, only the last value is kept. Search the input for the key if a value seems to have disappeared.
Works well with the JSON Formatter
- JSON Validator: check whether JSON is valid without changing its layout.
- JSON Viewer: explore a large document as a collapsible tree and copy paths.
- JSON Diff: compare two versions of a response, ignoring key order.
- JSON to TypeScript: turn the formatted response into TypeScript interfaces.
- JSON Minifier: compress it back to a single line before sending.
Frequently asked questions
Does sorting keys change my data?
No. Only the order of object keys changes; values and array order stay exactly as they were. Sorted keys make two documents easier to compare.
Why is my JSON invalid?
The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys and comments, none of which are allowed in standard JSON. The error message points to the first problem.
Are large numbers like 64-bit IDs kept exactly?
Yes, in current browsers. JavaScript numbers lose precision above 2^53, so JSON.parse turns 12345678901234567891 into 12345678901234567000. The formatter keeps the original digits of such integers and tells you how many it found.
Can I load JSON from an API URL?
Yes. From URL downloads the file in your browser, without cookies, and never through our server. The server must allow cross-origin reads (CORS), as most public APIs and raw GitHub files do; otherwise save the file and open it.
Is my JSON uploaded anywhere?
No. Parsing and formatting happen in your browser with the built-in JSON parser, so the data never leaves your device.
What is the difference between formatting and validating?
Both parse the input and report the first syntax error with its line and column. Formatting also rewrites the layout; validation leaves your text unchanged.
Can I format JSON Lines (NDJSON)?
Not as one document: each line of JSON Lines is a separate value. Format one line at a time, or wrap the lines in [ ] and separate them with commas.
Guides and tutorials
- JSON & Data Formats
How to Generate TypeScript Types from JSON API Responses
Turn a JSON sample into TypeScript interfaces, then fix what a generator can't know: nullable fields, optional keys, unions, dates and runtime validation.
· 6 min read
- JSON & Data Formats
How to Compare Two JSON Files and Find the Real Differences
Why a text diff of JSON shows noise, how a semantic JSON diff ignores key order and formatting, and how to compare JSON in the browser, with jq and in Python.
· 5 min read
- Programming Languages
How to Run Python Code Online (No Install, With Input)
Run Python code online in your browser: a first program, input() and stdin, reading many lines, which modules work, and how to read a Python traceback.
· 5 min read
- JSON & Data Formats
Common JSON Syntax Errors and How to Fix Them
Trailing commas, single quotes, comments, NaN and invisible characters: what each JSON parse error means, how to find the exact line, and how to fix it.
· 8 min read
Related tools
HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.
SQL Formatter
Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.