JSON Formatter
Format & validate JSON
0 characters · 0 lines
100% client-side — your JSON is processed in this browser and is never uploaded, logged or stored.
What Is a JSON Formatter?
JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data. It is defined by RFC 8259 and ECMA-404, and it is the default data format for web APIs, configuration files and log pipelines. JSON is quick for machines to parse, but once it has been minified onto a single line it is very hard for a person to read.
A JSON formatter — also called a JSON beautifier or pretty-printer — takes raw JSON and rewrites it with consistent indentation and line breaks, so the shape of the objects and arrays inside it becomes obvious at a glance. This tool does that the moment you paste, and it works in the other direction too: Minify removes every optional space and newline to produce the smallest valid JSON for sending over the network.
Everything runs locally in your browser using the built-in JavaScript JSON engine, so it is fully compliant with the JSON specification, handles the full range of Unicode and UTF-8 characters (emoji, accented letters and non-Latin scripts included), and never sends your data anywhere. Alongside formatting you can sort keys, repair common mistakes, convert to and from escaped string literals, and process newline-delimited JSON (NDJSON) — with no sign-up and nothing to install.
How to Use
Paste or type your JSON into the input box.
Set the options: indent, Sort keys (A‑Z / Z‑A), Collapse depth, Remove empty values, Syntax highlight, Wrap output.
Click Format to pretty-print, Minify to compress to one line, or Repair to fix comments, trailing commas and loose quotes.
Use Validate for a syntax check (with a duplicate-key warning), Escape / Unescape for string literals, or tick JSON Lines (NDJSON) for one record per line.
Resolve a JSON Pointer, load a file by Upload or drag-and-drop, then Copy, Download, or grab a Copy link.
Keyboard: Ctrl+Enter format · Ctrl+Shift+M minify · Ctrl+Shift+X validate. Your options and your last five inputs are stored in this browser only; Copy link puts the JSON in the URL fragment, which browsers never send to a server.
Features
- Format with 2-space, 4-space or Tab indentation
- One-click minification for compact payloads
- Colour syntax highlighting of keys, strings, numbers and keywords, with a wrap toggle
- Sort object keys A‑Z or Z‑A, recursively
- Collapse deep nesting to a chosen depth for a quick overview of large documents
- Remove empty values (
null,"",[],{}) throughout the document - Auto-format as you type, with every option remembered in this browser
- Repair almost-JSON: strips
//and/* */comments, converts single quotes, quotes bare keys, drops trailing commas - Escape / unescape JSON string literals (handy for embedding JSON in JSON)
- JSON Lines (NDJSON) mode: pretty-print or emit canonical one-record-per-line output
- Duplicate-key detection with line numbers (
JSON.parsesilently keeps the last one) - Resolve a JSON Pointer (RFC 6901) to pull one value out of the document
- Load data by uploading or drag-and-dropping a
.json/.ndjsonfile (up to 15 MB) - Structure readout: object, array and key counts, value-type breakdown, nesting depth, longest string, largest array and byte size
- Live character and line counters on both input and output
- Local history of your last five inputs, one click to restore
- Shareable Copy link that keeps the JSON in the URL fragment — never sent to a server
- Keyboard shortcuts and screen-reader-friendly status messages
- Clear line/column error reporting on invalid JSON
- Copy to clipboard or download as a
.json/.ndjsonfile - 100% client-side — nothing leaves your browser
Benefits of Formatting JSON
- Readability — indentation exposes nesting and grouping, so you find the field you need without counting brackets.
- Faster debugging — a formatted API response or log line is far quicker to scan for the value that is wrong.
- Cleaner diffs — formatting, and optionally sorting keys, makes version-control diffs show real changes instead of whitespace noise.
- Errors caught early — validation reports the exact line and column of a syntax error before it reaches your build or your users.
- Smaller payloads — minifying before you ship removes bytes you do not need in production while you keep the readable copy for development.
Who Uses This Tool
Backend and API developers checking request and response bodies; frontend developers inspecting fetch results; QA and test engineers building fixtures and asserting on payloads; data engineers cleaning up exports and NDJSON dumps; DevOps and SRE staff reading structured logs; technical writers preparing examples for documentation; and students learning how JSON is structured. Anyone who reads or writes JSON by hand benefits from a fast, private formatter.
Common JSON Errors and How to Fix Them
- Trailing commas —
[1, 2, 3,]is valid JavaScript but not JSON. Remove the last comma, or click Repair. - Single quotes — JSON strings and keys must use double quotes, so
'name'has to become"name". - Unquoted keys —
{name: "Ada"}must be{"name": "Ada"}. - Missing or extra brackets — every
{needs a matching}and every[a matching]; the error message points at where the parser gave up. - Comments — JSON has no comment syntax, so
//and/* */must be removed (Repair does this). - Unescaped characters — literal newlines, tabs or double quotes inside a string must be written as
\n,\t,\". - Invalid numbers — leading zeros (
007), a trailing dot (5.),NaNandInfinityare not valid JSON numbers. - Encoding issues — a stray byte order mark (BOM) or non-UTF-8 bytes at the start of the document will fail parsing.
JSON Formatting Best Practices
Use two-space indentation — it is the most widely used convention and keeps lines short. Keep files UTF-8 encoded without a BOM. Sort object keys when you want stable, reviewable diffs. Only minify for transport or storage, never as your working copy. Validate JSON in CI so a malformed fixture fails the build instead of a running service. For large collections of records, prefer NDJSON — one JSON value per line — so the data can be streamed and processed line by line.
Examples
Before (minified):
{"name":"Ada","active":true,"roles":["admin","editor"]}
After (formatted):
{
"name": "Ada",
"active": true,
"roles": [
"admin",
"editor"
]
}
Common Use Cases
- Cleaning up an API response before reading it
- Minifying JSON config before shipping it to production
- Debugging a malformed JSON payload from logs
- Preparing readable JSON examples for documentation
Frequently Asked Questions
Is my JSON uploaded anywhere?
No. All formatting and validation happens locally in your browser using JavaScript. Nothing is sent to a server.
What indentation does Format use?
Format always re-indents with 2 spaces per nesting level, which is the most common convention for JSON.
How do I make JSON as small as possible?
Click Minify. It removes all unnecessary whitespace so the JSON is valid but takes up minimal space.
Why does it say my JSON is invalid?
The tool shows the exact line and column where parsing failed. Common causes are trailing commas, single quotes instead of double quotes, or unquoted keys.
What does the Repair button do?
It makes a best effort to turn "almost JSON" into valid JSON: it removes // and /* */ comments, converts single-quoted strings to double-quoted, adds quotes around bare object keys, and deletes trailing commas — then formats the result. Text inside strings is never changed. If something is still broken it tells you the remaining error.
What are Escape and Unescape for?
Escape turns the input into a single JSON string literal (quotes and newlines backslash-escaped), which is what you need when embedding JSON inside another JSON value. Unescape reverses that, and if the decoded text is itself JSON it pretty-prints it.
Does "Sort keys" change my data?
Only the order of object keys, which is not significant in JSON. Values, arrays and array order are left exactly as they are. It applies at every nesting level. Choose A‑Z or Z‑A.
Why does the tool warn about duplicate keys?
A JSON object should not contain the same key twice. If it does, JSON.parse silently keeps only the last value, which can hide bugs. The tool scans the raw text and reports each duplicate with its line number so you can decide which value is correct.
What is the JSON Pointer field?
JSON Pointer (RFC 6901) is a standard syntax for addressing one value inside a JSON document, for example /address/geo/lat or /items/0/id. Type a pointer and click Resolve to see just that value. An empty pointer returns the whole document.
What do "Collapse depth" and "Remove empty values" do?
Collapse depth folds anything deeper than the level you set into a { … n keys } placeholder, which is useful for scanning a large document. Remove empty values drops keys and array items whose value is null, "", [] or {}. Both change only the output; your input is left alone.
Is the "Copy link" private?
The link stores your JSON in the URL fragment (the part after #), which browsers never transmit to a server, so pasting the JSON into this tool via a link stays entirely client-side. The fragment does appear in your browser history and anywhere you paste the link, so only share links for data you are comfortable sharing. Very large inputs cannot fit in a link — use Download instead.
What is JSON Lines (NDJSON) mode?
Tick JSON Lines (NDJSON) to treat the input as one JSON value per line. Format pretty-prints each record, Minify produces canonical one-line-per-record NDJSON, and Validate reports the first line that fails. Dropping a .ndjson file switches the mode on automatically.
Can I open a file instead of pasting?
Yes. Click Upload file or drag a .json, .ndjson or .txt file onto the input box. The file is read locally in your browser with the File API and is never uploaded.
Is my data stored between visits?
Your formatting options and a preview of your last five inputs are saved in this browser's local storage so the tool is convenient to reuse. Clear them any time with Clear history or your browser's site-data controls. Nothing is sent to a server.
Is there a size limit?
There's no hard limit for pasted text, and uploaded files up to 15 MB are accepted. Very large documents (several megabytes) may be slow to format since everything runs in your browser's JavaScript engine.
Can I download the formatted result?
Yes, click Download to save the current output as a data.json file.
Related JSON Tools
When you need more than formatting, JsonCherry has focused tools for each job: JSON Validator for strict syntax checking, JSON Tree Viewer for an expandable view of the structure, JSON Path Tester to extract values with JSONPath, JSON Diff Checker to compare two documents, and converters for CSV, YAML and XML.
Privacy
This tool runs entirely in your browser. The JSON you paste, upload or drop is parsed locally with JavaScript and is never transmitted to a server, logged or stored. Closing the tab clears everything except your formatting preferences and the short local history, which stay in this browser's local storage. See our Privacy Policy and Cookie Policy for details.