JSON repair
POST /api/json-repairRepair 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.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
json | string | yes | The 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
POST /api/json-repair$0.001 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example 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
}| Field | Type | Always present | In the example |
|---|---|---|---|
repaired | string | yes | {"name":"Ada","tags":["eng","math"],"score":null} |
changed | boolean | yes | true |
fixCount | number | yes | 8 |
fixKinds | object | yes | 6 fields: unquoted-key, single-quotes, trailing-comma, comment and 2 more |
fixes | array of objects | yes | 8 items in the example |
returned | number | yes | 8 |
matched | number | yes | 8 |
complete | boolean | yes | true |
truncated | boolean | yes | false |
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
jsonis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Free tier: no outbound network call leaves the server for this tool, so proof-of-work (16 leading zero bits of sha256) pays for it.
- A
GETorHEADto /api/json-repair returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
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
Parse a datetime from any format (ISO 8601, Unix timestamp in seconds or milliseconds, RFC 2822, or natural date string).
JSON lint
Check JSON text and point at the first syntax error: its line, column, character position (offset), the path.
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
Parse XML into a JSON object tree (attributes under _attrs, text under _text; repeated elements become arrays).
A2A Agent Card validate
Validate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags.
Amortization schedule
Build the full per-period amortization schedule for a fully-amortizing loan.