What JSON cleaning means in practice
Cleaning JSON is a wider operation than formatting. A formatter assumes the input already parses; a cleaner accepts JSON-flavoured text and tries to make it parseable. The two are complements — clean first, format second.
Common sources of dirty JSON are JavaScript files where someone copied an object literal, configuration files written by hand, model output with markdown fences and prose, and log lines where multiple JSON fragments got concatenated.
Things the cleaner removes or rewrites
AI JSON Repair handles the patterns that make JSON.parse throw.
- // line comments and /* block comments */ left over from JS sources.
- Trailing commas after the last item in arrays and objects.
- Single-quoted keys and string values from JS object literals.
- Unquoted keys (still valid in JS, never valid in JSON).
- Markdown code fences such as ```json and the closing ```.
- Surrounding prose like 'Here is the JSON:' or 'Result:'.
What cleaning will not do
Cleaning is a syntactic pass, not a semantic one. It will not invent missing fields, fix a wrong type, or guess what a field should be when the value is corrupted beyond recognition. If the original input is so broken that there is no clear original intent, the cleaner returns the best parseable version it can and you should review the result before trusting it.
For data with semantic constraints (required fields, enum values, value ranges), pair cleaning with JSON Schema validation. Run cleaner first to make the input parseable, then validate against your schema to confirm it is also correct.