About this endpoint
What it does
Repairs broken JSON text, takes the JSON out of surrounding prose when needed, and returns the parsed result with every fix it applied. If you send a JSON Schema, it also checks the repaired data against that schema.
Request Body
| Parameter | Type | Description |
|---|---|---|
| json | String | Required. The broken JSON text, or a whole model answer with prose around it. Max 1,000,000 characters. |
| coerce | Boolean | When true and a schema is sent, casts obvious type mismatches ("12" to 12, "true" to true, a single value to [value]) and lists each cast in fixes. Default: false. |
| schema | Object | A JSON Schema to check the repaired data against. Remote $ref values are not fetched. The format keyword (for example email) is not enforced. |
| extract | ENUM | Which JSON block to use when the text holds several. Allowed values: first, largest, all. Default: first. With all, data is an array of every block. |
Response
Returns a JSON object with count and items. count is the number of rows in items. Each request returns one row.
| Parameter | Type | Description |
|---|---|---|
| count | Integer | Number of rows in items. |
| items[].data | Any | The parsed JSON value. Can be an object, array, string, number, boolean or null. null when parsing failed. |
| items[].json | String | The same value as compact, strictly valid RFC 8259 JSON text. null when parsing failed. |
| items[].valid | Boolean | true only when the input was already valid JSON and needed no repairs. |
| items[].repaired | Boolean | true when broken input was repaired, or coerced to match the schema. false when the input was already valid or could not be parsed. |
| items[].fixCount | Integer | Number of repairs and casts applied. |
| items[].fixes | Object Array | One entry per repair. Empty when nothing was changed. |
| items[].fixes[].type | String | Kind of repair: code_fence, prose_removed, single_quotes, unquoted_key, trailing_comma, python_literal, comment, truncated_closed or coerced. |
| items[].fixes[].detail | String | Plain description of the change. |
| items[].fixes[].at | Integer | Character offset in the input. null for coerced entries. |
| items[].truncated | Boolean | true when the input ended early and open strings, arrays or objects were closed for you. |
| items[].inputChars | Integer | Length of the input text in characters. |
| items[].schemaValid | Boolean | true when the data matches the schema, false when it does not. null when no schema was sent. |
| items[].schemaErrors | Object Array | Schema problems, each with path, message and validator. Empty when the data is valid or no schema was sent. |
| items[].error | String | Present only when no JSON value could be found. |
| items[].errorAt | Integer | Character offset of the failure. Present only with error. |
| items[].ms | Number | Processing time in milliseconds. |
| items[].cached | Boolean | Present and true when the row was served from a cache. |
| items[].cacheAgeSeconds | Integer | Age of the cached row in seconds. Present only when cached is true. |
Errors
A request the API cannot accept returns status 400 with a JSON body that has code (invalid_input), error and message. This happens when json is missing, when extract is not one of the allowed values, and when the text contains hidden or control characters such as zero width joiners.
Text that holds no JSON at all returns status 200 with data set to null and an error message in the row.
Notes
- Check
fixesbefore you rely on the result. Repairs are heuristic. - When a key is missing its colon or closing quote, the repair can merge or drop values without an
error. Comparedatawith your source for such input. - Numbers with very long decimals can be shortened without an entry in
fixes. - With
coerceset totrue, a string such as"0012"becomes the number12.



