How to Format, Validate and Fix JSON in Your Browser

By Alok Singh · Published

An API returns a 4,000-character single line of JSON, and somewhere in it is the field you need. Or a config file you edited by hand now crashes the app with "Unexpected token } in JSON at position 1873". Position 1873 is not a helpful clue. JSON formatter indents JSON, validates it, and when it's broken tells you the line and column with the surrounding text.

Steps

  1. Paste or type JSON into the box.
  2. Press Format to indent, Minify to compress, or Repair and format for JSON that has comments or trailing commas.
  3. Copy or download the result, or open the tree view to explore nested data.

Strict validation, helpful errors

Validation uses your browser's built-in strict JSON parser, which follows the same rules any API or JSON.parse call will. When it fails, you get the line, the column and a short excerpt of the text around the problem, so you can jump straight to it.

The usual suspects, roughly from most to least common:

  1. A trailing comma after the last item in an object or array.
  2. Single quotes instead of double quotes.
  3. Keys without quotes, as in JavaScript object literals.
  4. Comments, which JSON doesn't allow (even though many config files pretend it does).

Repair and format

For hand-edited JSON, Repair and format fixes those four problems automatically: it strips comments and trailing commas, converts single-quoted strings to double-quoted ones and quotes bare keys, then validates the result. That makes it handy for turning a JavaScript object pasted from code, or a JSONC config, into valid JSON.

Repair can't read your mind, though. A missing closing brace or a truncated response still needs you to find where the data stopped.

Tree view

For deeply nested API responses, the tree view lets you expand and collapse levels instead of scrolling hundreds of lines. It shows the first few thousand items so it stays responsive; for anything bigger, use Format and search the text.

Does formatting change the data?

Format and Minify only change whitespace and line breaks. The values are untouched. Sort keys reorders the keys alphabetically, which JSON treats as meaningless, so it's safe for comparing two objects but may annoy a teammate who arranged the keys by hand.

Practical uses

Tips

Privacy

According to the page, JSON is formatted inside the page and kept in the tab only. That matters when the payload includes tokens or customer data. The page shows Google ads, like the rest of the site.

FAQ

Why is my JSON invalid? Usually a trailing comma, single quotes, unquoted keys or comments. The error points to the exact spot.

Can it handle large files? Yes, several megabytes; the tree view is capped for speed.

Does formatting change my data? No, only whitespace. Sort keys only changes key order.

Can it fix my JSON? Repair and format fixes the common hand-editing mistakes.

Got a wall of JSON? Paste it into JSON formatter.

— Alok Kumar Singh


← All guides