In this section · 03 Fix itFix invalid JSON
03 · Fix it · Repair broken JSON
Fix invalid JSON: comments, quotes and commas
Turn a config full of comments, bare keys and trailing commas into JSON that parses, in one press of Repair.
Input
// copied from config/staging.js
{
service: 'orders-api',
region: "eu-west-1",
retries: 3,
timeoutMs: undefined, // set per request
endpoints: [
'/v1/orders',
'/v1/refunds',
],
tls: true,
}Do
- Paste the input into the left pane of the editor.
- Press Repair in the editor band.
Result
Removed trailing commas (2)
Quoted bare property names (6)
Converted single-quoted strings (3)
Replaced undefined with null
Removed comments (2)
{
"service": "orders-api",
"region": "eu-west-1",
"retries": 3,
"timeoutMs": null,
"endpoints": [
"/v1/orders",
"/v1/refunds"
],
"tls": true
}Most broken JSON is not really broken. It is a JavaScript object pasted out of a source file, a config that someone annotated, or a value printed by a Python shell. A strict parser rejects all of it at the first character it dislikes, and then you are left hunting for quotes by hand. The input above is one such document — a staging configuration lifted straight out of a .js file — and one press makes it valid. The rest of this guide is about what that press did, what else it copes with, and where it deliberately stops. The Repair broken JSON topic has a card for each of those other cases.
Count the problems first
It is worth reading the input closely, because five different things are wrong with it at once and that is normal for pasted config. There is a line comment at the top and another after undefined. None of the six property names carries quotes. Three strings use single quotes. undefined is not a JSON value at all. And two trailing commas close the array and the object, which JavaScript forgives and JSON never has. A parser reports only the first of the five, which is why fixing this by hand feels like it never ends.
Repair it in the editor
- Open the editor and paste the text into the left pane. The status bar reads Invalid JSON, and the Code view underlines where the parser stopped.
- Press Repair in the editor band, the strip of controls just above the two panes, under On the left pane. The same command sits in the pane’s own toolbar, where it turns amber while the document does not parse.
- Read the status bar. It lists every kind of fix it made and how many times, most structural first, on one line joined with middle dots:
Repaired — Removed trailing commas (2) · Quoted bare property names (6) · Converted single-quoted strings (3) · Replaced undefined with null · Removed comments (2)The status bar now says Valid JSON. In Compare mode each pane holds a document of its own, so Repair acts on the one you last worked in, and the band names it before you press: On the left pane or On the right pane.
What did not change
Notice what the result keeps: the indentation, the line breaks inside the array and the order of the keys are exactly as they were. Repair rewrites only the characters that were wrong, so the comment line vanished with its own line break, and what you get back is still recognisably the file you pasted. That matters on a two-thousand-line config, where reformatting everything would make the one real fix impossible to spot in a review.
If the result is not what you wanted, a single undo puts the original back: ⌘Z on a Mac, Ctrl+Z on Windows or Linux. The repair lands as one change, so there is nothing to step through. And every result is parsed again before it is allowed to replace your text — when the fixes it knows about are not enough, the document is left untouched and the status bar reads Could not repair this automatically — the remaining errors are marked in the editor.
Reading the list of fixes
The line the status bar prints is not decoration; it is the record of what was done to your file, and it is worth a glance every time. Each entry names one kind of change and, where it happened more than once, how many times — so Quoted bare property names (6) above accounts for every key in the document, and a number smaller than you expected is a sign that part of the file was not what you thought it was.
The order is deliberate. Structural repairs come first, because those are the ones that alter the shape of the document: brackets closed, values wrapped in an array, a missing comma inserted. Cosmetic ones come last, where straightened quotes and stripped comments cannot change the meaning of anything. If you are going to check one line of the list, check the first.
Two entries are worth treating as warnings rather than fixes. Replaced undefined with null and Replaced NaN and Infinity with null mean a value was lost rather than translated, because JSON has no spelling for any of the three. The document is now valid and one of its fields is empty; only you can say whether that field mattered.
Private by construction
Configs like the one above tend to carry hostnames, keys and customer identifiers. Repair runs inside the editor page, on your own machine, with no request made to any server, so it is safe to use on files you could not paste into a random website. It keeps working with the network disconnected, too.
Open the editor and paste your own document, or go back to Repair broken JSON for the answer from a model, the log file with no brackets, and the cases Repair refuses. Started from an error message instead of a file? The JSON error messages pages explain each one by the words your runtime printed.