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.
Automatically repairs malformed, unquoted, trailing-comma, and broken JSON strings generated by LLMs or legacy systems.
—Automatically repairs malformed, unquoted, trailing-comma, and broken JSON strings generated by LLMs or legacy systems.
{ name: 'Alice', age: 30, // comment\n }{\n "name": "Alice",\n "age": 30\n}Fixes unquoted keys, single quotes, comments, and trailing commas.
A normalized JSON document conforming to RFC 8259 specifications.
Your input is processed entirely in your browser and never sent to a YAS server.
curl -X POST "https://yas.sh/api/v1/tools/json-repair" \
-H "Content-Type: application/json" \
-d '{"input":"{ name: 'test', count: 1, }"}'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();import requests
r = requests.post("https://yas.sh/api/v1/tools/json-repair", json={"input":"{ name: 'test', count: 1, }"})
data = r.json()| Field | Type | Required | Description |
|---|---|---|---|
| input | string | Yes | Malformed JSON text |
{ "slug": "json-repair", "repaired": "{
"name": "test",
"count": 1
}", "valid": true }Repair broken, unquoted, and malformed JSON strings.
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).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.
Models wrap JSON in code fences, add trailing commas and occasionally truncate. Repair salvages the response instead of discarding it and retrying.
A JSON line cut off by a size limit can often be closed and parsed, recovering the fields that did arrive.
A config broken by a trailing comma or a smart quote can be repaired, then re-saved in valid form.
Comments, unquoted keys and trailing commas are legal in those dialects and illegal in JSON; repair converts them to strict JSON.
What this tool deliberately does not do, and where it will disagree with other implementations.