About the JSON Formatter
API responses, configuration files and data exports often arrive as one unbroken line of JSON that is almost impossible to read. This JSON formatter checks that the data is valid, reports the line and column of any error, such as a trailing comma or a missing quote, and prints it back with clean, consistent indentation so the structure is easy to follow. It can also minify formatted JSON for sending or storing. Everything runs in your browser, so tokens, keys and customer data are never uploaded. For browsing large documents as a collapsible tree, try the JSON Viewer, and to compare two versions, the JSON Diff tool.
When parsing fails, you get a plain-language description of the problem and the line and column where the parser stopped. Nearly all broken JSON comes from a short list of slips: a comma after the final item, single quotes where JSON requires double quotes, a quotation mark inside a string that was not escaped, or a closing bracket that never arrived. Instead of hunting through a long file, you go straight to the spot.
The checking is done by the JSON parser built into your browser, and your input is never run as code, so it is safe to paste JSON from a source you do not trust. Nothing is sent to a server at any point, which matters when a payload contains access tokens, API keys or customer records.
How to use the JSON Formatter
- Paste the JSONAn API response, a configuration file or any piece of JSON.
- Pick the indentationTwo spaces, four spaces or a tab, to match your project.
- Run FormatValid JSON is printed neatly; invalid JSON produces an error with the line and column.
- Save the outputUse the copy button or download it as a .json file.
JSON Formatter features
- Validation and pretty-printing in one step
- Indentation of two spaces, four spaces or a tab
- Errors that point to the exact line and column
- Minify option that returns everything to one line
- Optional alphabetical sorting of keys
- Counts of nodes and nesting depth
- Copy or download the result
- Uses the browser's own JSON parser and never evaluates code
Common uses
- Reading an API response that came back as a single line
- Checking a configuration file before a deployment
- Locating the syntax error that made a build fail
- Laying out two JSON documents the same way to compare them
- Including tidy JSON in documentation or a bug report
JSON in practice: reading API responses, the errors that break parsing, numbers, Unicode and schemas
JSON is the everyday language of web APIs, configuration files and data exports, so being able to read it quickly and fix it confidently saves developers and analysts a lot of time. This guide works through a broken API response, explains the errors that cause most parsing failures, covers the less obvious traps with large numbers and Unicode, compares JSON with JavaScript objects and introduces JSON Schema for validating structure.
A worked example: a broken response
Suppose a hand-edited test response looks like this, line by line:
{"order": 1042, "city": "Lahore", "items": [1, 2, 3],}
It fails to parse because of the trailing comma before the closing brace. Removing it gives valid JSON, and formatting then shows the structure clearly: an object with three keys, the last holding an array. The parser's line and column number point straight at the comma, which is much faster than reading a long line by eye.
The errors behind most failures
- Trailing commas after the last item in an object or array.
- Single quotes instead of double quotes around strings and keys.
- Unquoted keys, which JavaScript allows but JSON does not.
- Comments, which standard JSON does not allow.
- Special values such as
undefined,NaNorInfinity, which JSON cannot represent.
Most of these come from copying JavaScript objects and treating them as JSON. They look similar, but JSON is stricter.
Large numbers lose precision
JSON itself puts no limit on number size, but JavaScript and many other languages store numbers as 64-bit floating point values, which can represent integers exactly only up to 9,007,199,254,740,991. Larger IDs, common in some databases and social media APIs, silently change when parsed. APIs often send such IDs as strings for this reason, and you should keep them as strings rather than converting them to numbers.
Unicode and escapes
JSON text is normally UTF-8, so Urdu, Arabic and emoji can appear directly in strings. Some systems escape them as sequences such as ل, which are equivalent. If text appears as garbled characters, the problem is usually an encoding mismatch earlier in the pipeline rather than the JSON itself.
Indentation conventions
Two spaces of indentation is common in JavaScript projects and four in Python, while some teams use tabs. The choice does not affect the data. What matters is consistency within a project, ideally enforced by an automatic formatter, so that changes show up clearly in version control.
JSON Schema
For data exchanged between systems, JSON Schema describes the expected structure: which keys are required, what types values must have and what ranges are allowed. Validating against a schema catches problems such as a missing field or a number sent as a string before they cause errors deeper in an application.
Formatting for debugging
When an API call misbehaves, formatting the request and response side by side often reveals the problem immediately: a nested object where an array was expected, a misspelled key or a null where a value should be. Copying formatted JSON into bug reports also makes them much easier for colleagues to read.
Safe parsing
JSON should always be parsed with a proper JSON parser, never by evaluating it as code. Evaluating text from an untrusted source can execute malicious code, while a parser only ever produces data. Modern languages all include safe JSON parsers.
Common mistakes
- Treating JavaScript object syntax as valid JSON.
- Converting very large IDs to numbers.
- Hand-editing JSON without validating it afterwards.
- Mixing indentation styles within one project.
Related tools
To explore large documents, use JSON Viewer. To compare two versions, try JSON Diff Checker, and to shrink JSON for transfer, JSON Minifier.
Formatting in code editors
Most code editors can format JSON with a keyboard shortcut or automatically on save, using built-in tools or extensions. Setting this up across a project means everyone's files look the same, and formatting changes never clutter code reviews. A browser-based formatter is handy for quick checks away from your usual editor.
Duplicate keys
JSON technically allows an object to contain the same key twice, but most parsers keep only the last value and silently discard the first. Duplicate keys usually indicate a mistake, such as a badly resolved merge conflict. Some validators warn about them, which is worth enabling for configuration files.
Dates in JSON
JSON has no date type, so dates travel as strings, usually in ISO 8601 format, or as numeric timestamps. Agreeing on one format across an API, and documenting whether times are in UTC, prevents misunderstandings between front-end and back-end developers.
Null or missing?
A key with a null value and a missing key can mean different things: null often means "known to be empty", while a missing key may mean "not provided". APIs that treat them differently should document the distinction, and clients should handle both to avoid errors.
Privacy
Formatting and validation run entirely in your browser. Your JSON is never uploaded or stored.
Further reading: JSON for Beginners: Syntax, Common Errors and Formatting.
Frequently asked questions
Why is my JSON rejected even though it looks correct?
The most common causes are a trailing comma after the last item, single quotes instead of double quotes, keys without quotes, or an invisible character pasted from a word processor. The error position is usually just past the real mistake, so look one character back.
Can the formatter handle JSON that contains comments?
No. Comments are not allowed in standard JSON, so a file that contains them is not valid and is rejected. For formats such as JSONC used by some editors, remove the comments before formatting.
Will formatting alter my data?
No. Only the spacing changes. Keys, values, data types and the order of array items stay exactly the same, unless you deliberately switch on the option that sorts keys alphabetically.
Is my JSON uploaded anywhere?
No. Your browser's own parser does all the work inside this page, so API keys, access tokens and customer records in the payload never leave your device.
Is there a size limit?
Files of several megabytes are fine on an ordinary computer. Much larger files take a moment longer and use more memory in the browser tab, but they are still processed on your machine and never uploaded.
What is the point of sorting keys?
Sorting puts the keys of every object in the same alphabetical order, so two versions of the same data line up neatly and differences stand out clearly in a diff tool or when you compare them by eye.