Valid JSON is strict. Humans and language models are not. You end up with a blob that is almost JSON: a trailing comma after the last property, single quotes instead of double, a comment someone swore was fine, an object cut off mid-stream.

JSON.parse throws. Your pipeline stops. The fix is usually mechanical — if you can stand to stare at brackets long enough.

The Usual Breakage

  • Trailing commas in objects/arrays
  • Smart quotes from Word or Slack (“” instead of "")
  • Unquoted keys
  • Ellipsis leftovers (...) from truncated model output
  • Concatenated JSON values with junk text before/after

Manual Triage

Paste into a formatter. Read the error line number. Fix the first syntax error; re-parse; repeat. For small payloads that works. For agent loops that emit broken JSON every third call, you want a function, not a ritual.

JSON repair as a $1 / x402 utility

JSON repairer takes the broken string and returns valid JSON when repair is possible. Humans can pay $1 per call in the browser. Agents should call POST https://gate402.app/v1/json-repair, handle the 402, pay, and retry — the same pattern as the rest of the Gate402 utility set.

When Repair Is the Wrong Tool

If the model omitted half the schema, “repair” may invent structure you should not trust. Prefer repair for syntax damage, then validate against your schema. Garbage semantics still need a better prompt or a structured-output mode.

Pair It With CSV Cleanup

Data wrangling often arrives as CSV that needs to become JSON (or the reverse). That is a separate $1 tool: CSV ↔ JSON.

The Takeaway

Do not hand-edit trailing commas in a production agent path. Automate the syntax salvage, validate the result, move on. Repair JSON for $1 when you want that as a product instead of a gist you maintain forever.