LLM JSON Repair and Schema Enforcer API
Pricing
from $0.50 / 1,000 json repaireds
LLM JSON Repair and Schema Enforcer API
Deterministic engine that repairs truncated JSON, unescaped quotes, trailing commas, and markdown wrappers from LLM outputs.
Pricing
from $0.50 / 1,000 json repaireds
Rating
0.0
(0)
Developer
Nadim Hider
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
11 days ago
Last modified
Categories
Security
Limited permissionsShare
A deterministic, zero-latency engine that repairs malformed, truncated, or unescaped JSON produced by Large Language Models (LLMs) and autonomous agents. Strips markdown fences, fixes trailing commas, inserts missing closing brackets, autocasts numeric strings, and optionally validates outputs against strict JSON Schema definitions.
Why Use This Actor?
Autonomous agents frequently crash in production because LLMs output malformed JSON:
- Unescaped inner quotes inside string values.
- Trailing commas before closing braces.
- Truncated closing brackets caused by context limits.
- Markdown code block fences wrapping the payload.
This Actor eliminates LLM JSON errors deterministically without making expensive recursive calls back to OpenAI or Anthropic.
Dual Output Envelope (Agent Native)
Every output record contains both structured data and a pre-rendered markdown summary ready for immediate LLM context consumption:
{"id": "item-101","success": true,"meta": {"processing_time_ms": 2.4,"items_count": 1},"data": {"repaired_json": {"name": "Autonomous Agent","status": "active","tokens": 450,"tools": ["search", "calculator"]},"schema_valid": true,"schema_errors": [],"fixes_applied": ["Stripped markdown code fences", "Fixed JSON syntax anomalies", "Autocast numeric strings"]},"markdown_summary": "### JSON Repair Summary\n- Status: Success (Repaired in 2.4ms)\n- Schema Valid: True\n- Fixes Applied: Stripped markdown code fences, Autocast numeric strings\n\n```json\n{\n \"name\": \"Autonomous Agent\",\n \"status\": \"active\",\n \"tokens\": 450,\n \"tools\": [\"search\", \"calculator\"]\n}\n```"}
Input Schema
| Field | Type | Default | Description |
|---|---|---|---|
items | Array of Objects | Sample Broken JSON | Array of objects with id and raw_text strings to repair. |
enforce_schema | Object | {} | Optional JSON Schema to validate and enforce on the output. |
autocast_numbers | Boolean | true | Automatically converts numeric strings like '45' to integers. |
Pay-Per-Event (PPE) Pricing
- Primary Event:
json-repaired - Cost: $0.0005 per repaired item ($0.50 per 1,000 repairs).
- Initial 5 seconds of compute are waived via
apify-actor-start.
Integration Code in 10+ Languages
cURL
curl -X POST "https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN" \-H "Content-Type: application/json" \-d '{"items": [{"id": "1", "raw_text": "{\"key\": \"value\",}"}]}'
Python
from apify_client import ApifyClientclient = ApifyClient("YOUR_API_TOKEN")run = client.actor("n4d.h1dr/llm-json-healer").call(run_input={"items": [{"id": "1", "raw_text": "```json\n{\"score\": \"95\",}\n```"}]})for item in client.dataset(run["defaultDatasetId"]).iterate_items():print(item["data"]["repaired_json"])
Node.js / TypeScript
import { ApifyClient } from 'apify-client';const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });const run = await client.actor('n4d.h1dr/llm-json-healer').call({items: [{ id: '1', raw_text: '{ name: "Agent", }' }]});const { items } = await client.dataset(run.defaultDatasetId).listItems();console.log(items[0].data.repaired_json);
Go
package mainimport ("bytes""net/http")func main() {url := "https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN"payload := []byte(`{"items": [{"id": "1", "raw_text": "{\"test\": 1,}"}]}`)http.Post(url, "application/json", bytes.NewBuffer(payload))}
Ruby
require 'net/http'require 'json'uri = URI('https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN')req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')req.body = { items: [{ id: '1', raw_text: '{"status": "ok",}' }] }.to_jsonres = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
PHP
<?php$ch = curl_init('https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN');curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['items' => [['id' => '1', 'raw_text' => '{"a": 1,}']]]));curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$res = curl_exec($ch);
Java
import java.net.URI;import java.net.http.*;public class Main {public static void main(String[] args) throws Exception {HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder().uri(URI.create("https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN")).header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString("{\"items\": [{\"id\": \"1\", \"raw_text\": \"{\\\"x\\\": 10,}\"}]}")).build();client.send(request, HttpResponse.BodyHandlers.ofString());}}
C# (.NET)
using System.Net.Http.Json;var client = new HttpClient();var payload = new { items = new[] { new { id = "1", raw_text = "{\"ready\": true,}" } } };await client.PostAsJsonAsync("https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN", payload);
Rust
use reqwest::Client;#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> {let client = Client::new();let res = client.post("https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN").json(&serde_json::json!({"items": [{"id": "1", "raw_text": "{\"key\": 1,}"}]})).send().await?;Ok(())}
Swift
import Foundationvar request = URLRequest(url: URL(string: "https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN")!)request.httpMethod = "POST"request.setValue("application/json", forHTTPHeaderField: "Content-Type")request.httpBody = try? JSONSerialization.data(withJSONObject: ["items": [["id": "1", "raw_text": "{\"ok\": true,}"]]])URLSession.shared.dataTask(with: request).resume()
n8n / Make.com Webhook Node
Add an HTTP Request node in n8n or Make:
- Method:
POST - URL:
https://api.apify.com/v2/acts/n4d.h1dr~llm-json-healer/runs?token=YOUR_API_TOKEN - Body Parameters:
{ "items": [ { "id": "={{ $json.id }}", "raw_text": "={{ $json.raw_llm_output }}" } ] }