JSON fundamentals
How to repair invalid JSON without hiding data changes
Repair common JSON problems while preserving an auditable view of every automatic change.
Document summary
A safe repair process for comments, trailing commas, unquoted keys, single quotes, invalid values, and incomplete structures.
Key takeaways
- Use strict, representative input before relying on output.
- Review structure, types, and edge cases instead of checking only visual formatting.
- Continue examples inside the connected Bacodev tool to verify the result.
Repair should be reviewable
Automatic repair can correct syntax, but it cannot always know the intended value. A safe tool shows the original, repaired output, and a list of changes.
Never replace an important source file without checking the repaired values and keeping a backup.
Common repairs that can be applied conservatively
- Remove comments from configuration copied from JavaScript.
- Remove commas immediately before a closing brace or bracket.
- Quote simple unquoted property names.
- Convert simple single quoted strings.
- Replace unsupported JavaScript values with null and flag the change.
Know when repair becomes ambiguous
Missing values, truncated files, unmatched quotation marks, and mixed fragments may have more than one plausible correction.
When the intent is uncertain, use the error location and surrounding context instead of accepting a guessed structure.
Review a repair before accepting it
{
// limit
limit: undefined,
}{
"limit": null
}Validate the repaired result
- 1
Parse the repaired output as strict JSON.
- 2
Compare key fields with the original source.
- 3
Check null replacements and removed comments.
- 4
Run schema validation if a contract exists.
- 5
Save the repaired file under a new name first.
The five breaks the repairer handles
Most invalid JSON falls into a small set of patterns. The repair tool recognizes trailing commas, comments, single-quoted strings and keys, unquoted keys, and JavaScript-style values such as undefined, NaN, and Infinity.
Each repair is conservative: the tool changes the minimum needed to make the document parse, and it lists every change so you can decide what to accept.
- Trailing comma after the last item in an object or array
- Line comments with // or block comments with /* */
- Single quotes instead of double quotes for strings
- Keys without quotes
- JavaScript constants such as undefined, NaN, and Infinity
Review the change list before you use the output
- 1
Open the JSON repair tool and paste the malformed document.
- 2
Run the repair and read the change list. Every correction is reported with its location.
- 3
Accept the repaired document or undo specific changes you do not agree with.
- 4
Validate the result once more in the JSON formatter before using it in code or configuration.
Frequently asked questions
Does repairing JSON change my data?
The repairer only fixes syntax. Values are preserved, and every change is listed so you can review it before accepting the output.
Why does the repairer not fix everything?
Some inputs are ambiguous, for example a missing comma between two values. The tool fixes unambiguous syntax errors and flags the rest for manual review.
Are comments valid in JSON?
No. Strict JSON has no comment syntax. The repairer removes or converts comments so the document parses, which is useful when you received JSON with comments from a config file.
Is my malformed document uploaded for repair?
No. Repair runs entirely in your browser with local JavaScript. Your data never leaves the device.