How to use the JSON Formatter & Validator
Updated · 3 min read
Minified API responses and hand-edited config files are hard to read and easy to break. Paste JSON here and it is instantly validated and re-indented. If something is wrong, you get the error message with its line and column, so you can fix it in seconds. Choose Minified under JSON indent to compress it back into a single line.
- Paste your JSON or drop a
.jsonfile into the input box. - Valid JSON is formatted immediately; invalid JSON shows an error with its position.
- Change JSON indent in Options to 2 spaces, 4 spaces, tabs or Minified.
- Copy the result or download it as a
.jsonfile.
Example
Input
{"id":7,"tags":["a","b"],"meta":{"ok":true,"score":9.5}}Formatted output
{
"id": 7,
"tags": [
"a",
"b"
],
"meta": {
"ok": true,
"score": 9.5
}
}Formatting changes only whitespace: keys keep their order and every value stays exactly the same, so the formatted and minified versions are interchangeable.
Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.
The most common JSON errors
- Trailing commas:
[1, 2, 3,]or{"a": 1,}are valid in JavaScript but not in JSON. - Single quotes: strings and keys must use double quotes —
'name'is invalid. - Unquoted keys:
{name: "Sara"}must be{"name": "Sara"}. - Comments:
// …and/* … */are not allowed in standard JSON. - Special values:
undefined,NaNandInfinitydo not exist in JSON; usenullor a string. - Smart quotes: text copied from Word or chat apps may contain “curly quotes”, which are not valid delimiters.
- Missing brackets: an unclosed
{or[is reported at the end of the input.
Beautify or minify?
Formatted JSON with indentation is for humans: code reviews, debugging and documentation. Minified JSON removes all optional whitespace, which makes payloads smaller for APIs, local storage and configuration embedded in other files. Two-space indentation is the most common convention in JavaScript projects, four spaces in Python, and tabs in some Go and PHP code bases.
Very large numbers
JavaScript, and therefore every browser-based tool, stores numbers as 64-bit floating point. Integers longer than 15–16 digits — such as some database IDs or Twitter/X snowflake IDs — cannot be represented exactly and change when parsed. The formatter warns you when your JSON contains such numbers; the safe fix is to store them as strings.
Convert while you are here
Once your JSON is valid, switch the target format to turn it into something else: CSV, Excel, YAML, XML or JSON Lines.
Do it in code
For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.
Python
# Pretty-print a file (Python 3.9+ also supports --compact to minify)
python -m json.tool data.json pretty.json --indent 2
Command line (jq)
jq . data.json # format with 2-space indentation
jq -c . data.json # minify to a single line
JavaScript
const pretty = JSON.stringify(JSON.parse(text), null, 2);
const minified = JSON.stringify(JSON.parse(text));
Frequently asked questions
Does the formatter fix errors automatically?
No — silently changing your data could hide real problems. It reports the error with its position, and the list above explains how to fix the most common mistakes.
Does formatting change my data?
No. Only whitespace is added or removed. Key order and values are preserved exactly, except for numbers too large for JavaScript, which you are warned about.
Can it validate JSON with comments (JSON5 / JSONC)?
No. Comments and trailing commas are not part of the JSON standard, so they are reported as errors. Remove them to get portable JSON.
Is my JSON sent to a server?
No. Parsing and formatting happen in your browser, so you can safely paste tokens, configuration or customer data.
What is the maximum size?
There is no fixed limit. Multi-megabyte files are processed in a background thread; the practical limit is your device's memory.