JSON guide

JSON Cleaner

Clean JSON-like text by removing comments, trailing commas, code fences and other parser-breaking syntax.

Open AI JSON Repair

How to do it

  1. Paste JSON-like text — copied from a JS file, an AI response, a config or a log.
  2. Run AI JSON Repair to remove comments, fences, trailing commas and similar noise.
  3. Validate the cleaned output, then format it with JSON Formatter.

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.

Examples

JavaScript object literal

Input

// from src/config.js
        const config = {
          host: 'localhost',
          port: 3000,
          features: ['ssr', 'edge',],
        }

Output

{
          "host": "localhost",
          "port": 3000,
          "features": [
            "ssr",
            "edge"
          ]
        }

The cleaner strips the comment, the variable declaration, removes the trailing commas and quotes the keys.

Recommended tool

Related guides

FAQ

What can a JSON cleaner fix?

Comments, single quotes, trailing commas, unquoted keys, markdown fences and surrounding prose.

Is cleaned JSON always correct?

Cleaning fixes syntax, not meaning. Review business-critical data after cleaning, especially when the original text is badly broken.

Can it clean API examples?

Yes. It is useful for copied examples that look like JavaScript objects instead of strict JSON.

What if the cleaner cannot recover the input?

Use the AI fallback for badly broken structures, then verify the result against your schema.

Can I run cleaning on JSONL?

Clean each line individually, or use JSON Lines to JSON to combine them into an array first.