JSON Formatter
Format, minify and validate JSON with the native parser. Error position hints where available. Output rendered as plain text — XSS safe. Runs locally.
Formatting JSON expands a single-line API response, configuration file or log entry into an indented hierarchy where the relationship between keys and values is visible at a glance; the reverse compresses formatted content back onto one line to save space. This tool uses the browser's native JSON.parse and JSON.stringify with no third-party library, and renders the result as plain text, so nothing inside the JSON is ever executed.
It serves three common purposes: seeing the structure of an API response while integrating, checking syntax before committing a configuration, and chasing down an error such as Unexpected token. JSON is stricter than a JavaScript object literal — keys must be double-quoted, trailing commas are not allowed, and comments and undefined are unsupported — and most errors come from one of those differences.
Did this tool solve your problem?
Submitting sends the tool name, your input and the current result to the server. Please do not include ID numbers, phone numbers or other private data.
AI assistant It answers using your current input and result
Asking again sends your current input and result to the server once more. Please do not include private data.
How to use
- Paste the JSON.
- Beautify it, or minify it back onto one line.
- Read the error position if validation fails.
- Fix the usual suspects: unquoted keys, trailing commas, comments.
How it works
Formatting rules
Formatting uses JSON.stringify(obj, null, 2) - 2-space indentation, a space after each key's colon, arrays and objects expanded line by line, ready for reading or config review.
Minification rules
Minification removes every removable whitespace (inter-key spaces, newlines, indentation), producing single-line minimal JSON for API transport or cache writes.
How syntax errors are located
Error location: when JSON.parse throws, the browser error message's position is parsed and converted to line/column. Due to engine differences, some multi-line errors only report the error type without exact positions.
Code example
JavaScript Formatting and minifying in the browser
// Pretty-print: the third argument is the indent width
const pretty = JSON.stringify(JSON.parse(raw), null, 2);
// Minify back to a single line (smallest size)
const minified = JSON.stringify(JSON.parse(raw));
Shell Doing the same with jq
# Pretty-print
jq . data.json
# Minify
jq -c . data.json
# Read a single field
jq ".data.list[0].name" data.json
FAQ
JSON vs. JavaScript objects - what's the difference?
JSON is a plain-text data format: keys must be double-quoted, values limited to string/number/boolean/null/array/object, with no comments, single quotes, trailing commas or functions. JavaScript object literals are far looser. This tool validates against strict JSON.
Are trailing commas legal in JSON?
No. {"a":1,} is a syntax error in standard JSON (parsers like JSON.parse reject it). Config formats like JSON5 and JSONC allow trailing commas and comments, but those are not standard JSON.
Is my JSON uploaded?
No. Formatting, minification and validation all use the browser's native JSON.parse/stringify - nothing crosses a server, it works offline, and sensitive API responses and config files are safe to paste.
Does JSON support comments?
Standard JSON does not - double slashes or block comments fail validation. Use JSON5, JSONC or YAML for comments, or put notes in a dedicated field (like _comment). Comment-tolerant config files are tool extensions, not JSON.
What data types does JSON have?
Six: string, number, boolean (true/false), null, array and object. Strings need double quotes; numbers cannot have leading zeros; functions, undefined and Date objects are not legal JSON values.
Can formatted JSON be minified back to one line?
Yes. Formatting only adds indentation and newlines for reading; minification strips all extra whitespace - the data is identical. Use minified for transport and storage, formatted for debugging and review; switch freely.
Will huge JSON files lag the browser?
They can. JSON.parse is synchronous: hundreds of KB are fine, several MB may stutter noticeably. Split very large files or use a streaming CLI parser. Parsing stays local - no bandwidth, but bounded by browser memory.