Guide

How to format and validate JSON: a practical guide

Readable JSON is easier to review, debug and share. Validation comes first, because a formatter cannot reliably interpret a document that is not valid JSON.

What valid JSON looks like

JSON has a small set of rules. An object uses double-quoted keys, a colon between each key and value, and commas between members. Arrays use square brackets. Strings use double quotes. The values can be strings, numbers, booleans, null, objects or arrays.

JSON
{
  "name": "Ada",
  "active": true,
  "roles": ["admin", "reviewer"]
}

Single quotes, comments, trailing commas and unquoted keys are common in JavaScript, but they are not part of standard JSON. A strict parser reports them as errors. If you received a loose JSON-like file, Tool Kumar can identify common mistakes and offer a repair action while keeping the original input available.

How to find a JSON syntax error

  1. Paste the document into the Tool Kumar JSON viewer.
  2. Read the error line and column shown below the input.
  3. Check the character before the reported position. The missing comma or quote often appears immediately before it.
  4. Format the document again after the fix. Reformatting makes the next error easier to see.

Error positions point to where the parser stopped. That is not always where the mistake began. In this document the comma is missing at the end of line 2, but the parser reports line 3, because the next key is where it can no longer continue:

JSON
{
  "name": "Ada"
  "active": true
}

Format JSON for people and programs

Use pretty-printed JSON when someone needs to inspect or review a file. Keep indentation consistent, put one member on each line and preserve meaningful key order. Use minified JSON for a transport step when size matters and whitespace has no value.

Formatting does not change the data. It only changes whitespace. A good JSON formatter should also preserve large numbers, report invalid syntax clearly and avoid sending private documents to a remote service. Tool Kumar formats and validates JSON in your browser, so the input stays on your device.

Common JSON errors and how to fix them

MistakeExampleFix
Trailing comma[1, 2,]Remove the comma after the last object member or array item.
Single quotes{'id': 1}Use double quotes for strings and escape any inner double quotes.
Unquoted key{id: 1}Write object keys as strings, such as "id".
Missing value{"id": }Give every key a value after its colon.
Unclosed object or array{"ids": [1, 2}Match every opening brace or bracket with a closing one.
Invalid numberNaN, Infinity, 012JSON has no special numbers or leading zeroes. Use a plain number, a string or null.

Every one of these can be checked in the free JSON viewer and formatter: it points to the line and column of the first error and offers to repair the common ones for you.