JSON Repair
Repair malformed JSON from your agent.
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.
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.
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.
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.
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.
input: {"status": "ok", "total": 129.9, "items": [{"sku": "KB-01"}, {"sku": "MS
value: {"status": "ok", "total": 129.9, "items": [{"sku": "KB-01"}, {"sku": "MS"}]}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.
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.
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.
No. Repair fixes syntax only. A truncated answer becomes valid JSON with the last value cut short, so validate the result before using it.
Single quotes, unquoted keys, trailing commas, comments, Python True/False/None and missing closing brackets, within 64 KiB, depth 16 and 5,000 values.
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.
Repair malformed JSON from your agent.
Repair, validate and export to CSV as MCP tool calls.
Convert CSV to JSON while keeping IDs, ZIP codes and phone numbers exactly as written: every cell stays a string, quoted commas are respected and formulas are never evaluated.
Replace API keys, JWTs, emails, card numbers, IPs and phone numbers in logs with consistent placeholders before an agent pastes them into a model, a ticket or a vector store.
Split documentation into retrieval chunks that keep their heading path, never cut a fenced code block and carry stable ids and line ranges for citations.