All guides

How do I fix invalid JSON?

TL;DR

Paste the JSON into the formatter and click Format. Fix the first reported syntax error and try again. If the JSON formats successfully but an API rejects it, check the fields and types the API expects.

Tested example

We tested the following input with JSON.parse, the same parser used by our formatter. The first version is rejected. Removing the trailing comma lets the second version parse and format.

Invalid

{"name":"Mira","roles":["editor",]}

Corrected

{
  "name": "Mira",
  "roles": [
    "editor"
  ]
}

What to do

  1. Paste the JSON text into Input and click Format. If the error gives a position, start there and also check the preceding token. If the error says the input ended unexpectedly, check for an unfinished string, object, or array.
  2. Use double quotes around object keys and strings. Put a colon between a key and its value, and use commas only between items. Match every opening brace or bracket with its closing partner.
  3. Remove comments and replace JavaScript-only values such as undefined with values the receiving system accepts. JSON supports strings, numbers, booleans, null, objects, and arrays.
  4. Click Format again after each fix. When the Output panel shows the formatted JSON, review it before copying it back into the original request or file.

How to verify the result

Check that the formatted output still contains the intended keys and values. A successful format confirms the text parses as JSON. For API requests, also check the required fields, data types, and expected nesting.

If it still fails

If you copied an API response and see a parser error at the start, inspect the raw response. It may be an HTML error page. If you copied code from a message or document, remove any surrounding Markdown code fences.

JSON formatter

Try the tool