Repair broken JSON text
repair_json_textRepair broken or incomplete JSON text, including model output with missing quotes, trailing commas, or cut-off brackets, and return the corrected value or confirm it was already valid.
Instructions
Repair broken or incomplete JSON, including output from language models.
Use this when you have JSON in the conversation that may be missing quotes, have trailing commas, or be cut off. It is plain code, not an AI model: it can close missing brackets and fix common syntax issues, but it cannot invent the data you meant to write. Already-valid JSON is returned as-is, with wasValid true and repaired false. Do not use it for a file on disk (use repair_json_file for files).
json_lines: if true, each non-empty line is a separate document. If false (default), the whole text is tried as one JSON value first. If that cannot be repaired and there are several lines, each line is then tried on its own.
For one document, returns {"wasValid", "repaired", "value", "text"}. For several documents, returns {"count", "failed", "documents": [...]}.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "repair_json_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The JSON text to repair. May be one value, or several JSON Lines. | |
| json_lines | No | If true, treat each non-empty line as its own JSON document. |