How to Repair Broken JSON from AI Output and Logs
Repair common JSON syntax problems locally, review every change, and validate the result before using it in code or automation.
Why almost-JSON appears so often
Logs, configuration fragments and generated responses frequently look like JSON without following the strict grammar. Common differences include comments, single-quoted strings, trailing commas, bare property names and Python-style True, False or None values.
Blind search-and-replace is risky because punctuation inside string values can look like syntax. A repair step should be narrow, deterministic and followed by a real JSON parse.
Use an explainable repair sequence
First preserve the original input. Apply only known transformations, then inspect a report of what changed. Finally parse the repaired text with a strict JSON parser and format it for review.
If the source contains Markdown fences or explanatory prose, separate the candidate JSON block before repairing it. If multiple interpretations remain possible, stop and correct the document manually instead of guessing.
- Remove supported comments without touching comment-like text inside strings.
- Normalize known literal differences such as True, False and None.
- Quote bare object keys and replace single quotes only when the structure is unambiguous.
- Remove trailing commas, then run a strict parse.
Validate meaning, not only syntax
Valid JSON can still be wrong. A repaired value may have the wrong type, lose an optional field or represent an incomplete AI response. Compare the result with the original intent and with a known-good example.
For API payloads, generate or apply a JSON Schema after syntax repair. For configuration changes, use a tree diff to isolate additions, removals and type changes before committing the result.
Keep sensitive payloads local
Production API responses and logs may contain customer data, credentials or internal identifiers. Repairing and formatting in the browser avoids sending that payload to a formatting service, but local execution does not replace your organization's handling policy.
Use JSON Repair for the explainable cleanup, JSON Formatter for line and column validation, and JSON Tree Diff or JSON Schema for the semantic review that follows.
Apply this workflow locally
Start with JSON Repair, keep the original input private and inspect the result before sharing or using it downstream.
Open JSON Repair →