JSON Repair

Turn loose JSON into strict JSON: comments, single quotes, bare keys and trailing commas.

JSON that almost parses

Editors and logs often emit JSON with comments, single quotes, unquoted keys, or a comma before the closing brace. A strict parser rejects that. This page rewrites those habits and pretty-prints the value. Comments are removed, not stored. A tree editor is JSON formatter. Comparing two values is JSON diff.

How to use it

  1. Paste the loose text. Update as you type is on, so the result refreshes while you edit. Convert runs the same step once.
  2. Clear All empties the input and the result.
  3. Copy Result copies the strict JSON.
  4. Show Example loads {name: 'Ada', n: 1, tags: ['a',],} and a // note line. The result is an object with name Ada, n 1, and tags containing a. The comment is gone.

What gets rewritten

// and /* */ outside strings are removed. Single-quoted text becomes a JSON string, and the escapes \n, \t, \r, \', \" and \\ become the characters they name. A bare word is quoted, except true, false and null, which stay keywords in any letter case. undefined, NaN and Infinity become null. A comma that has only space or a comment before } or ] is dropped. The result is indented by two spaces. Text that is already inside double quotes is copied through. If the rewrite is still not JSON, or the box is empty, the page reports invalid JSON.

Where people use it

  • A config copied from JavaScript.
  • An API sample that left a trailing comma.
  • A log line with a // comment beside the object.

Questions

The comment disappeared.

Repair builds strict JSON. Comments are not part of JSON, so they are removed rather than stored.

A number in quotes stayed a string.

Text that is already inside double quotes is left alone. Only bare words and single-quoted strings are rewritten.