json-fix is a blazing-fast, Rust-powered JSON repair library built for resilient data pipelines, GPT outputs, web scraping tools, and any system where malformed JSON sneaks in.
It detects and fixes broken JSON strings — from misescaped quotes to missing commas — using a curated sequence of regex-powered healing steps. Ideal for both CLI tools and backend services.
- ✅ Fixes unescaped or invalid quote issues
- ✅ Repairs trailing commas, missing brackets, and embedded key-value bugs
- ✅ Pure Rust — no unsafe, no dependencies outside
fancy-regex - ✅ Supports logs for each fix step
- ✅ Battle-tested against AI-generated JSON errors
- ✅ Easily embeddable as a library or CLI tool
use json_fix::fix_json;
fn main() {
let broken = r#"{ "name": "Momo, "age": 3 }"#;
let result = fix_json(broken);
if result.fixed != broken {
println!("✅ Fixed JSON:\n{}", result.fixed);
} else {
println!("⚠️ No changes made.");
}
}cargo add json-fixlet result = fix_json_syntax(broken);cargo run --example quick_fix# Optional: regenerate regex constants from the manifest
cargo run --bin regex_manifest_codegensrc/lib.rs– Public API entrypointsrc/orchestrator/– Full diagnostic → scope → fixer execution pipelinesrc/diagnostics/– Modular diagnosers powered byFixDiagnosticoutputsrc/fixers/– Trait-based modular fixers with scopedFixContextsrc/meta/regex_manifest_codegen.rs– Build tool: generates constants from manifestmanifest/regex_map.ron– One source of truth for regex patternssrc/generated_patterns/– Auto-generated constants (Lazy<Regex>) per categorytests/– Real-world fixer + diagnoser test suitebenches/– Criterion benchmarks
Regexes are declared once in manifest/regex_map.ron, then compiled into fast, type-safe constants by running:
cargo run --bin regex_manifest_codegenThis ensures:
- ✅ One source of truth
- ✅ No runtime string-key lookups
- ✅ All patterns are testable, traceable, and Fitrah-aligned