DevToolsmith

JSON Formatter and Beautifier

Paste JSON to pretty-print it with clean indentation. The formatter validates as you type, points to the exact line and column of any error, and can repair common mistakes like trailing commas and single quotes.

Runs 100% in your browser — nothing is uploaded

JSON input
Tip: drop a file here142 chars · 142 bytes · 1 line
✓ Valid JSON8 keysdepth 2142 B → 195 B

⚠ 1 number can’t be stored exactly in JavaScript ($.id: 1234567890123456789). Kept exactly here, but JSON.parse would change it.

Formatted JSON
195 chars · 195 bytes · 14 lines

What the formatter does

  • Pretty-prints with 2 spaces, 4 spaces or tabs, or minifies to a single line.
  • Validates as you type and shows the line, column and reason for the first error.
  • Repairs “almost JSON” copied from JavaScript, Python or config files.
  • Sorts keys alphabetically at every level, useful before committing or comparing files.
  • Warns about duplicate keys, which are technically allowed but silently lose data in most parsers.

Numbers and keys stay exactly as written

JavaScript stores every number as a double-precision float, so a formatter that runs your JSON through JSON.parse and JSON.stringify changes the data. This tool reformats the text itself and never converts values. The table below is generated from both code paths every time the site is built:

Case Input JSON.parse + stringify This tool
Integer above 2^53 Rounded to the nearest double; 64-bit IDs end up pointing at another record. {"id":9007199254740993} {"id":9007199254740992} {"id":9007199254740993}
Trailing zeros Same value, different text, which breaks signatures and byte-for-byte diffs. {"price":1.10} {"price":1.1} {"price":1.10}
Long decimal Cut to about 17 significant digits. {"pi":3.14159265358979323846} {"pi":3.141592653589793} {"pi":3.14159265358979323846}
Exponent Rewritten as a plain number. {"n":1E2} {"n":100} {"n":1E2}
Overflow Becomes Infinity, which JSON.stringify writes as null. {"big":1e400} {"big":null} {"big":1e400}
Negative zero The sign is dropped. {"z":-0} {"z":0} {"z":-0}
Duplicate key Only the last value survives; this formatter keeps both and warns. {"a":1,"a":2} {"a":2} {"a":1,"a":2}
Unicode escape Decoded to the character; the escape is gone. {"s":"caf\u00e9"} {"s":"café"} {"s":"caf\u00e9"}

The status bar warns when a number can’t be stored exactly in JavaScript or when an object repeats a key, so you know which values will change once your own code parses the document. Strings are copied unchanged, including \u escapes. Apart from whitespace (and key order when Sort keys is on), the only change is that a leading byte order mark is removed.

Format JSON on the command line and in code

# jq (also validates)
jq . data.json
jq --indent 4 . data.json
jq -S . data.json          # sort keys

# Python, no install needed
python3 -m json.tool data.json
python3 -m json.tool --sort-keys --indent 2 data.json

# Node.js
node -e 'console.log(JSON.stringify(JSON.parse(require("fs").readFileSync(0, "utf8")), null, 2))' < data.json
JavaScript
JSON.stringify(value, null, 2);    // 2 spaces
JSON.stringify(value, null, '\t'); // tabs

Need it compact instead? Use the JSON minifier. To compare two versions, use JSON Diff, and to query a large document, try the JSONPath tester.

For an incomplete response or copied object literal, use JSON Repair to review inferred changes beside the original. Formatting valid JSON does not reconstruct missing data.

Frequently asked questions

How do I format JSON?

Paste your JSON into the formatter above. It is validated and pretty-printed as you type, with 2 spaces by default. Choose 4 spaces or tabs, turn on Sort keys if you want alphabetical order, then copy or download the result.

Is it safe to paste sensitive JSON here?

Yes. Formatting runs entirely in your browser with JavaScript; nothing is uploaded, logged or stored. You can disconnect from the internet after the page loads and it keeps working. Share links store the data in the URL fragment, which browsers never send to the server.

Why does my formatted JSON show different numbers on other sites?

Most online formatters use JSON.parse, which converts every number to a 64-bit float. Integers above 9,007,199,254,740,991 (2^53 − 1), such as Twitter/X IDs or database bigints, get rounded, 1.10 becomes 1.1, 1e400 becomes null and duplicate keys disappear. This formatter reformats the text without converting values, so numbers and keys stay exactly as written.

Can it fix invalid JSON?

Often, yes. When the input is invalid, a Repair JSON button appears if the problem is one of the common ones: comments, trailing commas, single quotes, unquoted keys, Python True/False/None, NaN or missing commas. Check the result, since repair has to guess what you meant.

2 spaces or 4 spaces?

Both are valid; JSON ignores whitespace between tokens. 2 spaces is the most common choice (npm’s package.json, Prettier’s default, JSON.stringify examples); 4 spaces is common in Python projects because json.dumps(indent=4) is widespread. Pick whatever your project already uses.