REAL PAYMENTSBase (chain id 8453) · USDC payments have real value. Paid upstream failures are not automatically refunded.
Guide · JSON repair

Fix invalid JSON from LLM output.

Models often return almost-JSON: Python literals, trailing commas, comments, unquoted keys. This guide repairs a real example in your browser, then shows the case repair cannot fix — a truncated answer that parses but is wrong.

Try with your own data

Runs in this browser. No account, wallet or API key. Your input and result are not sent to InvokePort. API automation uses a scoped key.

01What usually breaks

JSON.parse rejects the whole answer when a model writes single-quoted strings, unquoted keys, a trailing comma, a // comment, or Python values such as True and None. The data is usually all there; only the syntax is off.

The example in the tool above contains every one of these. Run it: the repaired value has order_id "A-1042", both items, paid true and note null, and the response reports changed: true so your code knows a repair happened.

02Send only the JSON, not the prose around it

A bare ```json fence is removed. But if the model also wrote a sentence such as "Sure! Here is the order:" before the fence, that text becomes part of the repaired value — you get an array that mixes the sentence, the object and a stray quote character.

Ask the model for JSON only, or cut the text between the first { and the last } before repairing. Two separate objects in one answer ({"a": 1} {"b": 2}) are rejected as not repairable rather than guessed.

03Valid JSON is not the same as correct data

A model that hits its token limit stops mid-value. Repair closes the open string and brackets, so the result parses — but the last value is whatever was written before the cut.

Truncated input and its repaired value
input:  {"status": "ok", "total": 129.9, "items": [{"sku": "KB-01"}, {"sku": "MS
value:  {"status": "ok", "total": 129.9, "items": [{"sku": "KB-01"}, {"sku": "MS"}]}

04Check the repaired value before you use it

Treat changed: true as a signal to verify. Validate the value against the structure you expect — required fields, types, an enum or a length for identifiers such as SKUs — with the JSON Schema check. SKUs here are five characters, so "minLength": 5 rejects the truncated "MS".

If validation fails, ask the model again or route the record for review. Do not retry the repair: it is deterministic and will return the same value.

05Run it inside an agent

The same engine is available to agents as the invokeport_json_repair MCP tool, next to invokeport_json_schema and invokeport_json_csv. The JSON pipeline workflow chains repair, validation and CSV export and stops before export when validation fails.

Questions

Does repair send my JSON to a server?

Not on this page. The tool runs in your browser; the input and result are not sent to InvokePort. API and MCP calls are server-side and need a scoped key.

Can it recover data the model never wrote?

No. Repair fixes syntax only. A truncated answer becomes valid JSON with the last value cut short, so validate the result before using it.

Which mistakes does it fix?

Single quotes, unquoted keys, trailing commas, comments, Python True/False/None and missing closing brackets, within 64 KiB, depth 16 and 5,000 values.

How is this different from a JSON repair library?

If you control the code, a library such as jsonrepair is a fine choice. InvokePort is useful when an agent needs the same repair, validation and export steps as callable MCP tools with a scoped key, quota and call journal.

Next steps

Free · in browser

JSON Repair

Repair malformed JSON from your agent.