How the JSON Beautifier works
The beautifier reads your input with a tolerant parser written for relaxed JSON and JavaScript object literals. It accepts and repairs:
//,/* */and#comments, which are removed;- single-quoted strings, whose JavaScript escapes such as
\'and\x41are decoded; - unquoted property names, trailing commas, and missing commas between values on separate lines;
- number forms such as
+1,.5,5.,1_000and0xFF, which are converted to plain decimal numbers; undefined,NaN,Infinityand-Infinity, which becomenullbecause JSON cannot represent them;- Python-style
True,FalseandNone; - a leading
const name =,module.exports =orexport defaultand a trailing semicolon.
The repaired document is written out as standard JSON with the indentation you chose, and the status message lists each kind of repair that was made. Values that were already valid JSON, including large integers, are copied exactly. If the input cannot be repaired, for example because a text value has no quotes, the error shows the line and column.
How to use the JSON Beautifier
- Paste your loose JSON or JavaScript object into the input box, open a file, or select Load example.
- Choose the indentation you want: 2 spaces, 4 spaces or tabs.
- Select Beautify JSON, or press Ctrl + Enter (Cmd + Enter on a Mac).
- Read the status message to see which repairs were made, then copy the valid JSON or download it as a .json file.
Example
This JavaScript-style input:
// user
{
name: 'Ann',
age: 42,
roles: ['admin', 'dev',],
manager: undefined, /* unknown */
}
is repaired and formatted with 2-space indentation as:
{
"name": "Ann",
"age": 42,
"roles": [
"admin",
"dev"
],
"manager": null
}
The status message reads: Repaired and formatted as valid JSON: 2 comments removed, 3 single-quoted strings converted, 4 property names quoted, 2 trailing commas removed, 1 undefined/NaN/Infinity value replaced with null.
Common use cases
- Turning a JavaScript object copied from source code or the browser console into JSON.
- Cleaning configuration files that contain comments and trailing commas, such as tsconfig.json or VS Code settings, into strict JSON.
- Fixing hand-written test data that uses single quotes or unquoted property names.
- Converting Python-style output that uses True, False and None into JSON.
Common errors and how to fix them
- Could not repair the input at line N
- The beautifier fixes common relaxed-JSON problems, but it will not guess at structurally broken input such as a closing bracket missing from the end of the document. Add the missing bracket and run it again.
- Repairs were applied that you did not expect
- Every change is listed in the repair summary, including conversions such as Python's True, False and None becoming true, false and null. Read that list before using the output, because those conversions change the document.
- The input was already valid JSON
- Then there is nothing to repair and the result is simply reformatted. Use the JSON Formatter instead when you want strict validation rather than repair.
- A JavaScript object containing functions or undefined will not convert
- Those have no JSON equivalent, so they cannot be repaired automatically. Remove or replace them before pasting.
Frequently asked questions
What can the beautifier repair?
It removes //, /* */ and # comments and trailing commas, converts single-quoted strings, quotes unquoted property names, adds missing commas between values on separate lines, normalizes numbers such as +1, .5, 1_000 and 0xFF, converts True, False and None, and strips a leading const name =, module.exports = or export default and a trailing semicolon.
What happens to undefined, NaN and Infinity?
JSON has no way to represent them, so undefined, NaN, Infinity and -Infinity are replaced with null. The status message tells you how many values were replaced.
Is the output always valid JSON?
Yes. The repaired document is written as standard JSON, which the JSON Validator and any strict parser accept. If the input cannot be repaired, for example because a text value has no quotes at all, you get an error with the line and column instead of output.
Does it change values that were already valid?
No. Double-quoted strings and numbers that are already valid JSON are copied exactly as written, so large integers keep every digit. Only the parts that needed repairing are rewritten.
Is my data uploaded to your server?
No. The repair and formatting run in your browser, and the text you paste or open is not sent to our server.