Skip to content

JSON repair

FREE with proof-of-workor $0.001 in USDCPOST /api/json-repair

Repair broken JSON text and list its fixes with their line, column and offset (the first 200 in full; fixCount and fixKinds count all): trailing and extra commas, single or typographic quotes, unquoted keys, // and /* */ comments, missing closing brackets, unclosed strings, raw line breaks inside strings, NaN, Infinity and undefined (to null), Python True, False and None, and a Markdown code fence around the JSON. Send POST /api/json-repair with the required field json and pay $0.001 per call over x402 or MPP, or call it free by solving a proof-of-work challenge. It returns a JSON object with repaired, changed, fixCount, fixKinds, fixes and 4 more.

The answer always parses as strict JSON; when a fix would mean guessing (an unquoted word as a value, a mismatched bracket) it answers 400 with the reason and position instead. For a trailing comma, json-repair points at the comma and json-lint at the bracket after it. Input up to 100,000 characters.

Category: Live public dataTags: json repair fix clean parse llm-output trailing-comma commentsAlso found as: fix-json repair-json json-fix clean-json

Try in playground →

Parameters

NameTypeRequiredDescription
jsonstringyesThe broken JSON text (at most 100,000 characters) Also accepted as data, body, input, obj, object.

Example request

curl -i -X POST https://agent402.tools/api/json-repair \
  -H "Content-Type: application/json" \
  -d '{"json":"{name: '\''Ada'\'', tags: [\"eng\", \"math\",], // note\n score: NaN"}'

Without payment this returns HTTP 402 Payment Required with the exact price for json-repair; any x402 v2 or MPP client pays it and retries.

Watch a call get paid

RequestPOST /api/json-repair
402$0.001 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "repaired": "{\"name\":\"Ada\",\"tags\":[\"eng\",\"math\"],\"score\":null}",
  "changed": true,
  "fixCount": 8,
  "fixKinds": {
    "unquoted-key": 3,
    "single-quotes": 1,
    "trailing-comma": 1,
    "comment": 1,
    "non-json-literal": 1,
    "missing-bracket": 1
  },
  "fixes": [
    {
      "kind": "unquoted-key",
      "line": 1,
      "column": 2,
      "offset": 1,
      "message": "Quoted the key name"
    },
    {
      "kind": "single-quotes",
      "line": 1,
      "column": 8,
      "offset": 7,
      "message": "Replaced single quotes around a string with double quotes"
    },
    {
      "kind": "unquoted-key",
      "line": 1,
      "column": 15,
      "offset": 14,
      "message": "Quoted the key tags"
    },
    {
      "kind": "trailing-comma",
      "line": 1,
      "column": 35,
      "offset": 34,
      "message": "Removed a trailing comma before \"]\""
    },
    {
      "kind": "comment",
      "line": 1,
      "column": 39,
      "offset": 38,
      "message": "Removed a // comment"
    },
    {
      "kind": "unquoted-key",
      "line": 2,
      "column": 2,
      "offset": 47,
      "message": "Quoted the key score"
    },
    {
      "kind": "non-json-literal",
      "line": 2,
      "column": 9,
      "offset": 54,
      "message": "Replaced NaN with null"
    },
    {
      "kind": "missing-bracket",
      "line": 2,
      "column": 12,
      "offset": 57,
      "message": "Added the \"}\" for the \"{\" opened at offset 0"
    }
  ],
  "returned": 8,
  "matched": 8,
  "complete": true,
  "truncated": false
}
FieldTypeAlways presentIn the example
repairedstringyes{"name":"Ada","tags":["eng","math"],"score":null}
changedbooleanyestrue
fixCountnumberyes8
fixKindsobjectyes6 fields: unquoted-key, single-quotes, trailing-comma, comment and 2 more
fixesarray of objectsyes8 items in the example
returnednumberyes8
matchednumberyes8
completebooleanyestrue
truncatedbooleanyesfalse

From an MCP client

catalog.call {
  "slug": "json-repair",
  "params": {
    "json": "{name: 'Ada', tags: [\"eng\", \"math\",], // note\n score: NaN"
  }
}

On the hosted connector at https://agent402.tools/mcp, catalog.call runs json-repair free (rate-limited, no wallet). Local install: npx -y agent402-mcp@0.15.0.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.001" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/json-repair", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "json": "{name: 'Ada', tags: [\"eng\", \"math\",], // note\n score: NaN"
  }),
});

No wallet? Pay with compute

Fetch a challenge, solve the sha256 puzzle (16 leading zero bits, a fraction of a second of CPU), and resend with the X-Pow-Solution header:

import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=json-repair")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/json-repair", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"json":"{name: 'Ada', tags: [\"eng\", \"math\",], // note\n score: NaN"}) });

Related tools

Date format

FREE w/ computeor $0.001GET /api/date-format

Parse a datetime from any format (ISO 8601, Unix timestamp in seconds or milliseconds, RFC 2822, or natural date string).

JSON lint

FREE w/ computeor $0.001POST /api/json-lint

Check JSON text and point at the first syntax error: its line, column, character position (offset), the path.

CSV to JSON

FREE w/ computeor $0.002POST /api/csv-to-json

Parse CSV (quoted fields supported) into a JSON array of objects, using the first row as headers (header=false.

XML to JSON

FREE w/ computeor $0.002POST /api/xml-to-json

Parse XML into a JSON object tree (attributes under _attrs, text under _text; repeated elements become arrays).

A2A Agent Card validate

FREE w/ computeor $0.002POST /api/a2a-card-validate

Validate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags.

Amortization schedule

FREE w/ computeor $0.001POST /api/amortization

Build the full per-period amortization schedule for a fully-amortizing loan.