LocalDevTools

JSON Formatter & Validator

Paste JSON to pretty-print it, minify it or find exactly where it breaks. Large API responses are fine, and nothing leaves your browser.

Runs entirely in your browser. Your input is never uploaded or stored on a server.

How to format and validate JSON

  1. Paste your JSON into the input box, or click Load sample to try it.
  2. Click Format to pretty-print with 2 spaces, 4 spaces or tabs. Tick Sort keys A–Z if you want a stable key order, which makes two payloads much easier to compare.
  3. Click Minify to strip all whitespace, for example before putting JSON into an environment variable or a query string.
  4. If the JSON is invalid, the message tells you the line and column of the first problem and the cursor jumps there, so you can fix it in place.

The most common JSON errors

Almost every "invalid JSON" report comes down to one of a handful of mistakes. JSON is much stricter than JavaScript object syntax:

  • Trailing commas: {"a": 1,} is valid JavaScript but invalid JSON.
  • Single quotes: strings and keys must use double quotes. {'a': 1} fails.
  • Unquoted keys: {a: 1} fails; it must be {"a": 1}.
  • Comments: // and /* */ are not allowed in standard JSON (JSONC and JSON5 allow them, plain JSON does not).
  • Special values: NaN, Infinity and undefined are not JSON. Use null or a string.
  • Unescaped control characters: a literal newline or tab inside a string must be written as \n or \t.

Examples

Before: minified API response

{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true}

After: formatted with 2 spaces

{
  "id": 42,
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  },
  "active": true
}

Invalid input and the error you get

{
  "name": "Ada",
  "langs": ["en", "fr",]
}

The validator reports "Trailing comma before ]" at line 3, column 24 and places the cursor there.

Tips for working with large JSON

Very large numbers (above 253, such as some database IDs) lose precision when any JavaScript tool parses them, because JSON numbers become 64-bit floats. If you see an ID change after formatting, the source system should send it as a string. For files of tens of megabytes, minify or format once and download the result instead of scrolling the text box.

Frequently asked questions

Is my JSON sent to a server?

No. Parsing and formatting use your browser's built-in JSON.parse and JSON.stringify. You can disconnect from the internet after the page loads and the tool keeps working.

What is the difference between formatting and validating?

Validating only checks whether the text is legal JSON. Formatting first validates and then rewrites it with consistent indentation. Both report the same errors.

Why does the validator reject comments or trailing commas?

Because the JSON standard (RFC 8259) does not allow them. Some tools such as VS Code settings use JSONC, a relaxed variant. Remove the comments and trailing commas to get standard JSON that every parser accepts.

Does sorting keys change my data?

No. JSON objects are unordered by definition, so sorting keys produces equivalent data. Array order is never changed because arrays are ordered.

How big a file can I format?

It depends on your device memory, but files of several megabytes format in well under a second on a typical laptop. The limit is your browser, not a server quota.

Related tools

Last updated: