JSON Repair – Fix Broken JSON from LLM Output avatar

JSON Repair – Fix Broken JSON from LLM Output

Pricing

from $1.00 / 1,000 item repaireds

Go to Apify Store
JSON Repair – Fix Broken JSON from LLM Output

JSON Repair – Fix Broken JSON from LLM Output

Turns "almost JSON" from LLMs and logs into valid JSON. Removes code fences and chat text, fixes commas, quotes, comments and Python True/None, and closes cut-off output. Every row lists the fixes applied. Batch up to 10,000 strings per run. You're only charged for items that come back valid.

Pricing

from $1.00 / 1,000 item repaireds

Rating

0.0

(0)

Developer

Plainwren Studio

Plainwren Studio

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

7 days ago

Last modified

Features

Limited permissions

Share

What is JSON Repair?

JSON Repair turns broken or "almost JSON" from LLMs, chatbots and older scripts into valid JSON, and tells you exactly what it fixed. Paste one string or send up to 10,000 strings in one run. Each item becomes one dataset row, in the same order as your input.

It's plain, deterministic code: no AI calls, no third-party API, no login, no scraping. Nothing is stored beyond your run's own dataset.

Try it: open the Input tab, keep the two prefilled examples, and click Start.

Free single-string check in the browser: JSON formatter. Support: support@plainwrenstudio.com.

What can JSON Repair fix?

Every fix it makes is reported with a fix code, so you can see what changed.

Problem in your textFix code in the output
Markdown ```json code fences (also unclosed)removed_code_fence
Chat text before or after the JSON ("Sure! Here is the data:"); inside a code fence this shows as removed_code_fenceremoved_leading_text / removed_trailing_text
Trailing commas; double or leading commasremoved_trailing_comma / removed_extra_comma
Missing commasinserted_missing_comma
Single, smart (“ ”) or backtick quotesnormalized_quotes
Unquoted keys or bare-word valuesquoted_unquoted_keys / quoted_unquoted_values
//, /* */ and # commentsremoved_comments
Missing colon, or = instead of :inserted_missing_colon / replaced_equals_with_colon
Missing value ("a": ,)filled_missing_value (becomes null)
Python True / False / Noneconverted_python_literals
undefined, NaN, Infinityreplaced_non_json_values (become null)
Numbers like +1, .5, 2., 007fixed_number_format
Unescaped quotes inside strings (most cases)escaped_inner_quotes
Raw newlines or tabs inside stringsescaped_control_characters
Bad backslash escapes (an unknown escape like \d keeps its backslash, so Windows paths stay intact; \' becomes ')fixed_invalid_escape
... placeholders in place of array items or object members ([1, 2, ...]). Used as a value ("a": ...), it becomes the string "..." (quoted_unquoted_values)removed_ellipsis
] where } belongs (and the reverse)fixed_mismatched_bracket
Output cut off mid-string, object, array, number or true/false/nullclosed_truncated_* / completed_truncated_* / removed_incomplete_member
JSON wrapped in a JSON string ("{\"a\":1}")unwrapped_stringified_json
Byte-order mark at the startremoved_bom

Who is it for?

  • 🧑‍💻 Developers and AI-agent builders whose LLM calls return almost-valid JSON: models without a structured-output mode, older or local models, or streams that get cut off.
  • 🔗 No-code and automation users (Make, Zapier, n8n through Apify's integrations) whose LLM step breaks the next JSON step.
  • 🤖 MCP and agent users: a low-cost tool an agent can call to fix its own output.
  • 🧹 Data cleanup: logs or exports full of JavaScript-style objects or Python-style dicts.

Use cases

  • Fix broken JSON or invalid JSON from an LLM that wrapped the object in a code fence, added chat text, or used Python True / None.
  • Repair malformed JSON with trailing commas, missing quotes or cut-off output before the next step in Make, Zapier, n8n or an agent pipeline.
  • Clean logs or exports of JavaScript-style objects into valid JSON, with a fixes list on each row so you can see what changed.

How to repair JSON with this Actor

  1. Open the Input tab.
  2. Add your strings to Texts to repair (one malformed JSON or LLM reply per item), or use Single text for one item.
  3. Optional: turn on Pretty-print output to indent the result. Unwrap stringified JSON is on by default.
  4. Click Start.
  5. Get results from the Output tab, or download them as JSON, CSV or Excel. You can also call the Actor through the Apify API, schedule it, or connect it to other tools with Apify integrations.

Input example

{
"texts": [
"```json\n{name: 'Ada', skills: ['math',], active: True}\n```",
"Sure! Here is the data: {\"id\": 7, \"tags\": [\"a\" \"b\"], \"note\": \"truncat",
"no json here"
],
"pretty": false
}
FieldTypeWhat it does
textsarray of stringsOne malformed JSON or LLM output per item. Each becomes one row.
textstringOne item. Added after texts if you send both.
prettyboolean (default false)Indent the repaired string with 2 spaces.
unwrapStringifiedboolean (default true)If the input is a JSON string that contains a JSON object or array, return the inner value.

Output example

One dataset row per input item, in input order:

{"index":0,"ok":true,"data":{"name":"Ada","skills":["math"],"active":true},"repaired":"{\"name\":\"Ada\",\"skills\":[\"math\"],\"active\":true}","fixes":["removed_code_fence","quoted_unquoted_keys","normalized_quotes","removed_trailing_comma","converted_python_literals"],"error":null,"inputLength":58}
{"index":1,"ok":true,"data":{"id":7,"tags":["a","b"],"note":"truncat"},"fixes":["inserted_missing_comma","closed_truncated_string","closed_truncated_object","removed_leading_text"],"error":null,"inputLength":69}
{"index":2,"ok":false,"data":null,"repaired":null,"fixes":[],"error":"No JSON object or array found in input","inputLength":12}

(Row 1 is shortened here.)

Output fieldMeaning
indexPosition of the item, counting from 0 across texts, then text.
oktrue if valid JSON came back.
dataThe parsed JSON value.
repairedThe valid JSON as a string.
fixesFix codes for every change made. Empty if nothing was needed.
errorPlain-language reason when ok is false.
inputLengthLength of the input in characters. Present on every row; null if the item wasn't text.

A run summary is saved in the key-value store under OUTPUT:

{"total":3,"processed":3,"ok":2,"failed":1,"skipped":0,"stoppedAtLimit":false,"limitReason":null}

skipped = items not processed and not charged. limitReason is maxItems or spendingLimit when the run stopped early, otherwise null.

How much does it cost to repair JSON?

JSON Repair uses pay-per-event pricing, so you pay only for results:

  • $0.001 per repaired item (item-repaired): $1.00 per 1,000 repaired items. Charged once for each item that comes back with ok: true, including input that was already valid JSON.
  • Items that can't be repaired are free. They still appear in your dataset with ok: false and an error message.
  • A small Actor start fee of $0.00005 per run (Apify's standard start event).

Example: a run with 1,000 strings where 950 are repaired costs 950 × $0.001 + $0.00005 = about $0.95.

Apify's free plan includes monthly platform credit you can use to try it.

Limits

  • It's heuristic. Ambiguous input can become valid JSON that isn't what the model meant. Check the fixes list to see exactly what changed.
  • Cut-off output is closed, not recovered. A cut-off string stays cut off, and an incomplete last key is dropped (removed_incomplete_member).
  • Some inner quotes can't be fixed. A quote inside a string that's directly followed by a comma, colon, bracket or line break can be read as the end of the string, so the fix fails ("He said "hi", then left" comes out wrong).
  • One JSON value per string. If one string holds several JSON documents (for example JSONL), you get one of them (the longest), not all.
  • No JSON Schema validation yet. It makes JSON valid; it doesn't check it against your schema.
  • Size limits: up to 10,000 items per run, 5 million characters per item, nesting depth 512.
  • Items beyond 10,000 are skipped and not charged; the run still succeeds. The run summary shows how many were skipped. Send them in another run.
  • A result row must be under ~9 MB (Apify's dataset item limit), so items over ~4 MB come back as a free ok: false row with a "too large" error.

FAQ

Does it use AI to fix the JSON?

No. It's deterministic code that runs the same way every time, with no AI model or external API call. The same input always gives the same output.

What happens when an item can't be repaired?

You get a row with ok: false, data: null and a plain error such as "No JSON object or array found in input". You aren't charged for that item.

Am I charged for input that is already valid?

Yes. Valid input still comes back with ok: true and counts as one repaired item.

What happens if I hit my spending limit?

Each row is saved first and charged after. The run stops cleanly before any row it can't pay for, keeps everything already saved, and skips the rest without charging. The run still succeeds, and the summary (OUTPUT) shows how many items were skipped, with limitReason: "spendingLimit".

Can it bring back data the model never finished writing?

No. It closes open strings, arrays and objects so the JSON parses, but it can't invent missing content.

How is this different from open-source libraries like jsonrepair (JS) or json_repair (Python)?

Those are good if you can install and run code. This Actor is our own code (not a wrapper around those libraries) and is hosted. You don't install anything, you can send batches, you get a per-item fix report, and you can call it from the Apify API, integrations or MCP clients.

Can I use it from Make, Zapier, n8n or an AI agent?

Yes, through Apify's integrations and API, the same way as any other Apify Actor.

Is my data stored?

Only in your run's own dataset and key-value store, under your Apify account's normal storage retention. It doesn't send your text anywhere else.

Something got fixed wrong. What should I do?

Open an issue on the Actor's Issues tab with the input (remove anything private) and the output you expected, or email support@plainwrenstudio.com.