Skip to content

MTraveller/json-fix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crates.io Docs.rs

🛠️ json-fix

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.


🚀 Features

  • ✅ 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

🧪 Example

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.");
    }
}

📂 Usage

Install:

cargo add json-fix

As a library:

let result = fix_json_syntax(broken);

From CLI:

cargo run --example quick_fix
# Optional: regenerate regex constants from the manifest
cargo run --bin regex_manifest_codegen

📁 Project Structure

  • src/lib.rs – Public API entrypoint
  • src/orchestrator/ – Full diagnostic → scope → fixer execution pipeline
  • src/diagnostics/ – Modular diagnosers powered by FixDiagnostic output
  • src/fixers/ – Trait-based modular fixers with scoped FixContext
  • src/meta/regex_manifest_codegen.rs – Build tool: generates constants from manifest
  • manifest/regex_map.ron – One source of truth for regex patterns
  • src/generated_patterns/ – Auto-generated constants (Lazy<Regex>) per category
  • tests/ – Real-world fixer + diagnoser test suite
  • benches/ – Criterion benchmarks

📦 Manifest-Powered Regex System

Regexes are declared once in manifest/regex_map.ron, then compiled into fast, type-safe constants by running:

cargo run --bin regex_manifest_codegen

This ensures:

  • ✅ One source of truth
  • ✅ No runtime string-key lookups
  • ✅ All patterns are testable, traceable, and Fitrah-aligned

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages