---
title: Repair Broken JSON API
slug: json-repair-validate
url: https://apyhub.com/martin10291/service/json-repair-validate
provider: Martin Petrov
categories: [Ingestion Kit, Model Kit, Verification Kit]
tags: [json-repair, schema-validation, llm-output, data-cleanup, rfc8259]
auth: api_key
version: 1.0
service_type: sync
endpoints: 1
atoms: 100
mcp: true
---

# Repair Broken JSON API

Repair broken JSON API: send text from an AI model and get valid JSON back, with a list of every fix and optional schema checks. Free tier, no card.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/martin10291/json-repair-validate/json-repair-validate` | What it does Repairs broken JSON text, takes the JSON out of surrounding prose when needed, and ret… | 100 |

## Endpoint reference

### JSON Repair API - fix broken LLM JSON, validate schema

`POST https://api.eu.apyhub.com/martin10291/json-repair-validate/json-repair-validate` · 100 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `json` | body | string | yes | The broken JSON text, or a whole model answer with prose around it. Max 1,000,000 characters. Example: `Sure! Here it is:
```json
{name: "Ada", tags: ["math", "code",], active: True,…`. |
| `coerce` | body | boolean | no | 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`. Example: `true`. |
| `schema` | body | object | no | A JSON Schema to check the repaired data against. Remote $ref values are not fetched. The format keyword is not enforced. Example: `{"type":"object","required":["name","born"],"properties":{"born":{"… |
| `extract` | body | string | no | Which JSON block to use when the text holds several. With all, data is an array of every block. One of: first, largest, all. Default: `first`. Example: `first`. |

#### Quickstart

Send a model answer that has prose, a code fence and broken JSON, plus a schema to check it against.

```bash
curl -X POST "https://api.eu.apyhub.com/martin10291/json-repair-validate/json-repair-validate" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "json": "Sure! Here it is:\n```json\n{name: \"Ada\", tags: [\"math\", \"code\",], active: True, // note\n \"born\": \"1815\"}\n```",
    "schema": {"type": "object", "required": ["name", "born"], "properties": {"name": {"type": "string"}, "born": {"type": "integer"}, "tags": {"type": "array", "items": {"type": "string"}}}},
    "coerce": true
  }'
```

#### What you'll get back

Returns a JSON object with `count` and `items`. Each item holds the repaired `data`, the compact `json` text, the list of `fixes`, and the schema result in `schemaValid` and `schemaErrors`.

```json
{
  "count": 1,
  "items": [
    {
      "data": {"active": true, "born": 1815, "name": "Ada", "tags": ["math", "code"]},
      "fixCount": 9,
      "fixes": [
        {"at": 18, "detail": "markdown code fence removed", "type": "code_fence"},
        {"at": 0, "detail": "17 characters of text around the JSON ignored", "type": "prose_removed"},
        {"at": 27, "detail": "key quoted", "type": "unquoted_key"},
        {"at": 61, "detail": "trailing comma removed", "type": "trailing_comma"},
        {"at": 73, "detail": "True -> true", "type": "python_literal"},
        {"at": null, "detail": "/born: \"1815\" -> integer 1815", "type": "coerced"}
      ],
      "inputChars": 107,
      "json": "{\"name\":\"Ada\",\"tags\":[\"math\",\"code\"],\"active\":true,\"born\":1815}",
      "ms": 5.4,
      "repaired": true,
      "schemaErrors": [],
      "schemaValid": true,
      "truncated": false,
      "valid": false
    }
  ]
}
```

The `fixes` list is cut to 6 of its 9 entries here.

## About

## What it does
The Repair Broken JSON API turns broken JSON into valid JSON. Send text from an AI model or any other source, with or without prose around it, and the API returns the parsed data, a strict JSON string, and a list of every fix it made.

Put the text in `json` (up to 1,000,000 characters). The API fixes trailing commas, single quotes, unquoted keys, `//` comments, Python `True` and `False`, markdown code fences and input that ends early. If the text holds several JSON blocks, `extract` picks `first` (the default), `largest` or `all`. Add a JSON Schema in `schema` to check the repaired data. Set `coerce` to `true` to cast obvious mismatches, such as the string `"12"` to the number `12`. Each cast is listed in `fixes`.

Teams use the Repair Broken JSON API to clean up model answers before parsing them, to check structured output against a schema, and to log what changed in each response.

It repairs syntax only. Read `fixes` and `schemaValid` before you trust repaired data.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/martin10291/service/json-repair-validate
