Skip to content
YAS.SH
Developer🔒 Browser (client-side)API available📴 Works offlineintermediate

JSON Repair & Sanitizer

Automatically repairs malformed, unquoted, trailing-comma, and broken JSON strings generated by LLMs or legacy systems.

Data stays in your browser
Ready to runInstant execution
All tools →
Result

What does this tool do?

Automatically repairs malformed, unquoted, trailing-comma, and broken JSON strings generated by LLMs or legacy systems.

Why would I use it?

  • You received invalid JSON from an AI prompt or LLM completion with unquoted keys or trailing commas.
  • You need to sanitize human-edited configuration files before passing them to JSON.parse().
  • You are debugging API responses with single quotes or syntax mistakes.

Real-life example

Input
{ name: 'Alice', age: 30, // comment\n }
Output
{\n  "name": "Alice",\n  "age": 30\n}

Fixes unquoted keys, single quotes, comments, and trailing commas.

Input → Process → Output → Next

Input
Paste broken or malformed JSON text.
Process
Applies lexical normalization, quotes unquoted keys, strips trailing commas and comments.
Output
Strictly valid, formatted JSON string.
Next action
Copy the repaired JSON into your application or JSON validator.

Common mistakes

  • Assuming repair fixes logical data truncation (if JSON was cut off mid-string).
  • Not validating the repaired output with JSON Validator.
  • Using single quotes in strict JSON environments.

What the result means

A normalized JSON document conforming to RFC 8259 specifications.

Privacy & security

Your input is processed entirely in your browser and never sent to a YAS server.

API

Endpoint
POST https://yas.sh/api/v1/tools/json-repair
Request Header
Content-Type: application/json
cURL
curl -X POST "https://yas.sh/api/v1/tools/json-repair" \
  -H "Content-Type: application/json" \
  -d '{"input":"{ name: 'test', count: 1, }"}'
JavaScript
const res = await fetch("https://yas.sh/api/v1/tools/json-repair", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "input": "{ name: 'test', count: 1, }"
}),
});
const data = await res.json();
Python
import requests

r = requests.post("https://yas.sh/api/v1/tools/json-repair", json={"input":"{ name: 'test', count: 1, }"})
data = r.json()
FieldTypeRequiredDescription
inputstringYesMalformed JSON text
Success response
{ "slug": "json-repair", "repaired": "{
  "name": "test",
  "count": 1
}", "valid": true }

Repair broken, unquoted, and malformed JSON strings.

Error responses
  • 400 VALIDATION_ERROR — invalid input or unsupported option.
  • 413 PAYLOAD_TOO_LARGE — input exceeds the 64 KB limit.
  • 429 RATE_LIMIT_EXCEEDED — rate limit exceeded (60 req/min).
Limits
  • Maximum input: 64 KB per request.
  • Rate limit: 60 requests/min per IP address.
  • Authenticated accounts benefit from higher tier quotas.

JSON Repair & Sanitizer: technical reference, use cases and FAQ

How JSON Repair & Sanitizer works

Repair applies a sequence of targeted transformations to text that is nearly JSON: removing markdown code fences, stripping trailing commas, quoting unquoted keys, converting single quotes to double quotes, escaping literal control characters inside strings, and closing unterminated brackets and braces. After each transformation the result is re-parsed, so the process stops as soon as the document becomes valid.

This is heuristic reconstruction, not parsing, and it can be wrong. Deciding whether a stray quote terminates a string or belongs inside it is genuinely ambiguous, and the repair picks the interpretation that yields valid JSON — which is not always the intended one. That makes repair appropriate for recovering data you can verify and inappropriate as a permanent layer in a production pipeline.

When to use it: real-world scenarios

Recovering structured output from a language model

Models wrap JSON in code fences, add trailing commas and occasionally truncate. Repair salvages the response instead of discarding it and retrying.

Salvaging a truncated log entry

A JSON line cut off by a size limit can often be closed and parsed, recovering the fields that did arrive.

Reading a hand-edited config that will not load

A config broken by a trailing comma or a smart quote can be repaired, then re-saved in valid form.

Normalising JSON5 or JSONC input

Comments, unquoted keys and trailing commas are legal in those dialects and illegal in JSON; repair converts them to strict JSON.

Pro tips

  • Always inspect repaired output before using it. A successful repair means valid JSON, not correct JSON.
  • In production, prefer constrained decoding or a JSON-mode API for model output over repairing afterwards — it prevents the problem rather than patching it.
  • If the input is truncated, missing values are gone. Repair can close the structure but cannot invent the data that never arrived.
  • Log the raw input alongside the repaired result so a wrong reconstruction can be diagnosed later.

Limitations and edge cases

What this tool deliberately does not do, and where it will disagree with other implementations.

  • Ambiguous input can be repaired into a valid document that means something different from what was intended.
  • Truncated content cannot be recovered — only the structure can be closed.
  • Deeply nested damage may exceed what sequential heuristics can resolve.
  • Repair is not a substitute for fixing the producer; a pipeline that depends on it is fragile by construction.

Frequently asked questions

Can it fix any broken JSON?
No. It handles the common damage patterns — fences, trailing commas, unquoted keys, single quotes, unclosed brackets. Severely corrupted or truncated input may be unrecoverable, and some repairs are guesses.
Is repaired JSON safe to use in production?
Only after validation. Repair optimises for producing valid JSON, which is not the same as producing the intended data. Verify the fields you depend on.
Why does LLM output need repairing so often?
Models generate text, not syntax trees, and are prone to markdown fences and trailing commas. Constrained decoding or a provider's JSON mode is the structural fix.
Does it handle JSON5 and JSONC?
Yes — comments, unquoted keys and trailing commas are removed or converted, producing strict JSON that any standard parser accepts.
Ask YAS AI
🍪 Cookies & privacy. Essential cookies keep you signed in and remember language and theme. Google AdSense and reCAPTCHA are Google technologies: AdSense runs only after Accept All; reCAPTCHA loads on sign-in and contact forms. See how Google uses data: https://policies.google.com/technologies/partner-sites cookie policy · privacy policy.
Settings