Skip to content
Back

JSON Formatter

Format, validate and minify JSON, with optional key sorting.

Make JSON readable and check that it’s valid

JSON Formatter takes a squashed API response, config file or log entry and lays it out with consistent indentation so you can follow its structure. The same check tells you straight away whether the JSON is valid, and where it breaks if it isn’t.

Values are printed exactly as you pasted them. Long numbers such as 64-bit IDs are not rounded, 1.0 stays 1.0, and duplicate keys are kept rather than silently merged. Everything runs in the page, so API keys or customer data in the JSON stay on your machine.

How to format or validate JSON

  1. Paste your JSON into the JSON input box.
  2. Pick an indent: 2 spaces, 4 spaces or Tabs.
  3. Tick “Sort keys A–Z” if you want object keys in alphabetical order.
  4. Click Format for indented output, or Minify to put everything on one line.
  5. Click Copy result to take the output. If the JSON is invalid, the box stays empty and a message above it explains why.

Understanding the status message

  • Valid JSON — the message names the top-level type, such as “object with 4 keys” or “array with 20 items”, and the length of the output in characters.
  • Invalid JSON — you get the parser’s explanation and, in most browsers, a line and column. The cursor jumps to that spot in your input so you can fix it.
  • No location? Some browsers, Safari among them, don’t report a position, so only the message appears. Check for a missing comma, quote or bracket.

Where it helps

  • Debugging APIs: expand a one-line response to see which field is missing or null.
  • Editing config files: check a package.json or settings file is still valid after a manual change.
  • Comparing data: sort keys on two objects so they line up in the Text Diff Checker.
  • Shrinking payloads: minify JSON before storing it in an environment variable or a test fixture.

Why valid-looking JSON gets rejected

JSON is stricter than JavaScript

Keys and strings must use double quotes, trailing commas aren’t allowed, and comments aren’t part of the format. Values like undefined, NaN or a function also aren’t JSON. An object copied from JavaScript code often fails for one of these reasons.

Sorting is by character code

Sort keys A–Z orders keys by their character codes, so uppercase keys come before lowercase ones (“Zip” before “age”). Nested objects are sorted too, but arrays keep their original order because order inside an array has meaning.

JSON Formatter: common questions

Why does it say my JSON is invalid when it works in my code?

Your code may be reading a JavaScript object literal or a lenient format such as JSON5. Single quotes, unquoted keys, comments and trailing commas all need to be removed for standard JSON.

Will large numbers lose precision?

No. The output is rebuilt from your original text, so a number like 12345678901234567890 is printed exactly as entered instead of being rounded.

What happens to duplicate keys?

They’re kept in the output as written. Note that the key count in the status message counts each name once, because that’s how most programs will read the object.

Is my JSON sent anywhere?

No. Parsing, formatting and minifying all happen in your browser; nothing in the code sends the input to a server.