JSON Formatter
Format and validate JSON with configurable indentation, optional key sorting, and instant error feedback.
JSON input
Formatted output
JSON result
What is a JSON formatter?
A JSON formatter — also called a JSON beautifier or pretty-printer — takes compact or minified JSON text and reformats it with consistent indentation and line breaks, making the structure immediately human-readable. It also acts as a validator: if your JSON contains a syntax error (a missing quote, a trailing comma, mismatched brackets), the formatter catches it and reports exactly where the problem is so you can fix it without guessing.
JSON (JavaScript Object Notation) is specified in RFC 8259 and is the dominant data-interchange format for web APIs, configuration files, and database exports. Almost every developer works with it daily, yet raw API responses and minified production payloads are often a single unbroken line — impossible to read or debug without formatting.
How to use this tool
- Paste your raw, minified, or partially formatted JSON into the input editor on the left.
- Click the Format button (or press Ctrl+Enter).
- Choose indent size (2 or 4 spaces) and enable Sort keys to alphabetise every object's keys recursively.
- Use the Copy button to copy the result to your clipboard.
The formatter tolerates trailing commas and inline // comments (common in JSON5 and JSONC configuration files), stripping them silently before reformatting.
Input/output specification
| Property | Detail |
|---|---|
| Standard | RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format |
| Input tolerance | Accepts RFC 8259 JSON plus trailing commas and // line comments (JSONC/JSON5 supersets) |
| Output encoding | UTF-8 with BOM stripped; all non-ASCII characters preserved as-is |
| Max payload | Effectively unlimited for browser RAM; typical API responses format in < 1 ms |
| Processing | 100 % client-side — System.Text.Json.JsonDocument in WebAssembly; no network request |
Understanding JSON value types (RFC 8259 §3)
- Object — unordered set of key-value pairs in
{ }. Keys must be double-quoted strings; duplicate keys are technically undefined behaviour. - Array — ordered list of values in
[ ], separated by commas. - String — Unicode characters in double quotes. Escape sequences:
\"\\\/\b\f\n\r\t\uXXXX. - Number — integer or floating-point (no quotes, no hex/octal literals). Arbitrary precision numbers should use string form.
- Boolean —
trueorfalse(lowercase only). - Null —
null(lowercase only).
Common JSON validation errors
| Error | Cause | Fix |
|---|---|---|
| Unexpected token | Single quotes used instead of double quotes | Replace all ' with " |
| Trailing comma | Comma after the last item in an object or array | Remove the final comma before } or ] |
| Unexpected end of input | Missing closing bracket or brace | Ensure every { has a } and every [ has a ] |
| Invalid escape sequence | Backslash not followed by a valid escape character | Double the backslash: \\ for a literal backslash |
| Duplicate key | Same key appears twice in an object | Remove or rename the duplicate key |
Minified vs formatted JSON
Minified JSON strips all whitespace to reduce payload size. Formatted JSON restores indentation and line breaks. Minification reduces a typical formatted object by 15–30%; for debugging and development, formatted output is always preferable.
Common use cases
- Debugging API responses — paste the raw curl response, format it, inspect the field you need
- Config file review —
package.json,tsconfig.json,appsettings.jsonare easier to diff when consistently formatted - Webhook inspection — log the raw body, paste here, understand the event structure immediately
- Schema comparison — enable Sort keys to normalise two JSON objects before diffing
- NoSQL export cleanup — format single-line documents before reviewing
Native code equivalents
Production-ready snippets — same logic the tool runs, in your language// Format JSON with configurable indent
function formatJson(raw, indent = 2, sortKeys = false) {
const parsed = JSON.parse(raw);
if (sortKeys) return JSON.stringify(sortDeep(parsed), null, indent);
return JSON.stringify(parsed, null, indent);
}
function sortDeep(value) {
if (Array.isArray(value)) return value.map(sortDeep);
if (value !== null && typeof value === 'object') {
return Object.fromEntries(
Object.keys(value).sort().map(k => [k, sortDeep(value[k])])
);
}
return value;
}
const pretty = formatJson('{"b":2,"a":1}', 2, true);
console.log(pretty);
// {
// "a": 1,
// "b": 2
// }