DailyDeskTools home

JSON Formatter and Validator

Format, minify and validate JSON, with clear error positions and optional key sorting.

  • Free forever
  • No signup
  • Runs on your device
JSON FormatterRuns locally · nothing uploaded
Loading tool…

Watch the JSON Formatter in action

Paste an unreadable API response and turn it into clean, indented JSON for free. See how to find a parse error by its line and column, minify JSON again, and sort keys, all in your browser without sending your data anywhere.

Watch on its own page

How to use the JSON Formatter

  1. 1Paste your JSON into the left box.
  2. 2Pick 2 spaces, 4 spaces, tabs, or Minify.
  3. 3If the JSON is invalid, read the error with its line and column, then fix it.
  4. 4Optionally sort keys A–Z to make objects easier to compare.
  5. 5Copy or download the result.

Formatting and validation

The formatter parses your JSON with the browser's own strict parser, then writes it back out with the indentation you choose. If parsing fails, the error and its line and column are shown, so you can jump straight to the problem.

Common JSON errors

  • Trailing commas: {"a": 1,} is not allowed.
  • Single quotes: strings and keys must use double quotes.
  • Unquoted keys: {name: "Ada"} must be {"name": "Ada"}.
  • Comments: standard JSON does not allow // or /* */ comments.
  • Special values: undefined, NaN and functions are not valid JSON.

Minify or beautify?

Beautified JSON is easier for people to read and review. Minified JSON removes all optional whitespace, which makes files and API payloads smaller.

Sorting keys

Sorting object keys alphabetically does not change what the data means, but it makes two versions of a file much easier to compare. Arrays keep their original order.

Privacy

Your JSON is processed only in your browser, so it is safe to format API responses and config files that contain private data.

Reading a parse error

Messages differ between browsers and versions, but the causes are the same. The JSON standard, RFC 8259, is the reference for what counts as valid.

Message (typical) What it usually means
Unexpected token < at position 0 The response is an HTML page, often a login or error page, not JSON.
Unexpected end of JSON input The text is empty or cut off before the closing bracket.
Unexpected token u Something tried to parse undefined.
Unexpected token o at position 1 An object was parsed as text and became [object Object].
Expected property name or } A trailing comma, single quotes or an unquoted key.

Example

Pasting {"id":7,"tags":["a","b"],"ok":true} and choosing 2 spaces gives:

{
  "id": 7,
  "tags": ["a", "b"],
  "ok": true
}

Large numbers

The browser parser reads numbers as 64-bit floats, so integers above 9,007,199,254,740,991 can be rounded. If your IDs are longer than 15 digits, keep them as strings in the source.

Format JSON in code or the terminal

JSON.stringify(data, null, 2)
import json
print(json.dumps(data, indent=2, sort_keys=True))
python3 -m json.tool file.json

Next steps

To check what changed between two API responses, sort the keys of both and use the text compare tool to compare two JSON files. If a value is a Base64 string, the Base64 decoder opens it. Fields such as 1700000000 can be read with the Unix timestamp converter, and JSON placed in a query string needs the URL encoder first.

Frequently asked questions

Is my JSON sent to a server?

No. Parsing and formatting happen entirely in your browser.

Why does valid JavaScript fail as JSON?

JSON is stricter than JavaScript: keys need double quotes, and comments, trailing commas and single-quoted strings are not allowed.

Does sorting keys change my data?

No. Object key order has no meaning in JSON. Array order is kept exactly as it was.

How large a file can I format?

Files of several megabytes work on most computers. Very large files depend on your device's memory.

Why did a long number change after formatting?

Browsers parse JSON numbers as floating-point values, which are exact only up to 9,007,199,254,740,991. Larger integers lose their last digits, so store long IDs as strings.

What is the difference between JSON, JSONC and JSON5?

JSON is the strict format. JSONC (used in some editor settings files) allows comments, and JSON5 allows comments, single quotes and trailing commas. This tool validates strict JSON only.

Last updated · By the DailyDeskTools team

Built and written with AI assistance, then tested by hand by our team. How we make our tools