AnyRepair

GitHub stars

A Rust crate for repairing malformed structured data across 10 text formats (JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff, Java properties, and .env) and 6 binary media formats (PNG, JPEG, WAV, MP3, MP4, MOV).

Quick Start

Installation

[dependencies]
anyrepair = "0.3.0"

Basic Usage

use anyrepair::repair;

// Auto-detect format and repair
let malformed = r#"{"name": "John", age: 30,}"#;
let repaired = repair(malformed)?;
println!("{}", repaired); // {"name": "John", "age": 30}

CLI

# Install
cargo install anyrepair

# Auto-detect and repair
anyrepair repair input.json

# Format-specific repair
anyrepair repair input.json --format json
anyrepair repair input.yaml --format yaml
anyrepair repair config.ini --format ini
anyrepair repair app.properties --format properties
anyrepair repair .env --format env

# Show confidence score
anyrepair repair input.json --format json --confidence

# Preview changes as a diff (no output written)
anyrepair repair input.json --format json --diff --dry-run

# Dry-run without writing output
anyrepair repair input.json --format json --dry-run

# Machine-readable JSON output for CI
anyrepair repair input.json --format json --json --dry-run

# Require minimum confidence (exit with error if below threshold)
anyrepair repair input.json --format json --min-confidence 0.8

# Show which repair strategies were applied
anyrepair repair input.json --format json --explain --dry-run

# Generate shell completions
anyrepair completions bash > /etc/bash_completion.d/anyrepair
anyrepair completions zsh > _anyrepair
anyrepair completions fish > ~/.config/fish/completions/anyrepair.fish

# Batch process multiple files
anyrepair batch --input ./data --output ./repaired --recursive

# Stream large files
anyrepair stream --input large_file.json --output repaired.json --format json

# Repair binary/media files
anyrepair repair-binary damaged.png --output fixed.png
anyrepair repair-binary video.mp4 --format mp4 --dry-run
anyrepair repair-binary corrupted.wav --output fixed.wav

# Validation without repair
anyrepair validate --input input.json --format json

Docker

docker build -t anyrepair .
docker run --rm -i anyrepair repair --format json <<'EOF'
{"name": "John", age: 30,}
EOF

# MCP server
docker run --rm -i anyrepair anyrepair-mcp

What's New

v0.3.0 — Current

  • Media file repair — PNG, JPEG, WAV, MP3, MP4, MOV binary repair via BinaryRepair trait
  • Binary format detection — magic bytes auto-detection for 6 media formats with confidence scores
  • CLI repair-binary subcommandanyrepair repair-binary <file> [--format png] [--dry-run]
  • API: repair_binary(), repair_binary_with_format(), create_binary_repairer(), detect_binary_format()
  • 513 tests, all passing

v0.2.9

  • detect_format_with_confidence — format detection returns a confidence score (DetectionResult)
  • Docker image — multi-stage Dockerfile for CLI and MCP binaries
  • MCP versionanyrepair-mcp reports CARGO_PKG_VERSION (no more stale hardcoded version)
  • Integration tests for smart quotes, boolean variants, and prose extraction
  • 450 tests, all passing

v0.2.8

  • CLI: --diff, --dry-run, --json, --min-confidence, --explain, --color
  • Shell completions: anyrepair completions <shell>
  • LLM JSON strategies: smart quotes, boolean variants (yes/no/on/off), prose/preamble extraction
  • Optional strict feature for serde_json-backed JSON validation
  • Golden master + properties/env integration tests

v0.2.7

  • Auto-detect properties & envdetect_format() now recognizes .properties and .env files
  • Heuristic validator fixes — XML / CSV edge cases
  • Criterion benchmarks — All 10 formats + format detection + large-document throughput

v0.2.6

  • Minimal dependencies and json_util without serde
  • Heuristic validators for XML, TOML, CSV, and YAML

v0.2.0–0.2.5 (highlights)

  • Properties/.env formats, centralized registry, Python-compatible jsonrepair(), MCP, streaming

See CHANGELOG.md for full version history.

Why AnyRepair?

Structured data from LLMs, APIs, or manual editing is often malformed. AnyRepair fixes common issues:

  • JSON: Missing quotes, trailing commas, syntax errors
  • YAML: Indentation, missing colons
  • Markdown: Headers, links, fences
  • XML / TOML / CSV / INI / Diff: Format-specific repairs
  • Properties / .env: Key=value lines, sections, escaping

Key features:

  • Auto-detects format for all 10 text formats + 6 binary media formats
  • Deterministic heuristic repairs (no network, no ML)
  • Small dependency footprint (four runtime crates)
  • MCP server for Claude and other MCP clients
  • Streaming for large files
  • Binary media repair (PNG, JPEG, WAV, MP3, MP4, MOV)
  • Python-compatible JSON API
  • Optional strict feature for full serde_json parser validation
  • 578 tests (cargo test)

Dependencies

Kind Crates
Runtime regex, thiserror, clap, clap_complete
Optional serde_json (via strict feature)
Dev criterion, arbitrary, proptest

Parsing and validation for JSON, XML, TOML, CSV, and YAML use in-crate heuristics and json_util rather than heavyweight parser dependencies. Enable the strict feature for serde_json-backed JSON validation:

cargo build --features strict
cargo test --features strict

Usage Examples

Multi-Format Auto-Detection

use anyrepair::repair;

let json = repair(r#"{"key": value,}"#)?;
let yaml = repair("name: John\nage: 30")?;
let markdown = repair("# Header\n[link](https://github.com/yingkitw/anyrepair/blob/main/url")?;

Explicit key-value formats

use anyrepair::repair_with_format;

let props = repair_with_format("db.url jdbc:postgresql://localhost", "properties")?;
let env = repair_with_format("API_KEY = secret", "env")?;

Python-Compatible JSON API

use anyrepair::{jsonrepair, JsonRepair};

let repaired = jsonrepair(r#"{"name": "John", age: 30,}"#)?;

let mut jr = JsonRepair::new();
let repaired = jr.jsonrepair(r#"{name: "John"}"#)?;

Format-Specific Repairers

use anyrepair::{create_repairer, repair_with_format, traits::Repair};

let mut repairer = create_repairer("json")?;
let repaired = repairer.repair(malformed_json)?;
let confidence = repairer.confidence(&repaired);

let repaired = repair_with_format(malformed_yaml, "yaml")?;

Streaming Large Files

use anyrepair::StreamingRepair;
use std::fs::File;
use std::io::BufReader;

let input = BufReader::new(File::open("large_file.json")?);
let mut output = File::create("repaired.json")?;

let processor = StreamingRepair::with_buffer_size(65536);
processor.process(input, &mut output, Some("json"))?;

Binary Media Repair

use anyrepair::repair_binary;

// Auto-detect and repair
let repaired = repair_binary(&damaged_png_bytes)?;

// Explicit format
use anyrepair::repair_binary_with_format;
let repaired = repair_binary_with_format(&damaged_mp4_bytes, "mp4")?;

// Using the BinaryRepair trait
use anyrepair::{create_binary_repairer, BinaryRepair};
let mut repairer = create_binary_repairer("png")?;
let repaired = repairer.repair(&damaged_png_bytes)?;
let confidence = repairer.confidence(&damaged_png_bytes);

MCP Server Integration

cargo install anyrepair
anyrepair-mcp

claude_desktop_config.json:

{
  "mcpServers": {
    "anyrepair": {
      "command": "anyrepair-mcp"
    }
  }
}

Tools: repair, repair_json, repair_yaml, repair_markdown, repair_xml, repair_toml, repair_csv, repair_ini, repair_diff, repair_properties, repair_env, validate.

See MCP_SERVER.md for setup details.

Supported Formats

Format Common issues fixed Auto-detect
JSON Quotes, commas, booleans/null Yes
YAML Indentation, colons, lists Yes
Markdown Headers, links, fences Yes
XML Tags, attributes, entities Yes
TOML Quotes, arrays, tables Yes
CSV Quoting, commas Yes
INI Sections, = signs Yes
Diff Hunk headers, line prefixes Yes
Properties key=value, escaping, continuations Yes
Env KEY=value, comments, quoting Yes
PNG Chunk CRC, missing IEND, corrupted signature Yes
JPEG Missing SOI/EOI, trailing garbage, entropy data Yes
WAV RIFF/WAVE tags, chunk sizes, truncated data Yes
MP3 ID3v2 headers, frame sync, trailing nulls Yes
MP4 Box sizes, missing ftyp, truncated mdat Yes
MOV Box sizes, missing ftyp, QuickTime brand Yes

Performance

  • Strategy pipeline with priority ordering
  • Release profile optimized for size (opt-level = "z", LTO, strip)
  • Streaming for files larger than RAM
  • Fewer transitive dependencies for faster builds and smaller binaries
cargo build --release
cargo build --profile dist   # distribution profile in Cargo.toml

Testing

cargo test
Suite Tests
Library / modules 217
Completions / CLI extras 20
CLI 15
Integration 21
Binary integration 23
Binary comprehensive 65
Diff 35
Fuzz (proptest) 34
Streaming 26
Properties/env 25
Golden master 26
Corpus 17
Damage + complex damage + complex streaming 54
Total 578

See TEST_SUMMARY.md for more detail.

Comparison

Feature AnyRepair json-repair-rs json5 Python jsonrepair
Multi-format 16 formats (10 text + 6 media) JSON only JSON only JSON only
Auto-detection 16 formats No No No
Media repair PNG, JPEG, WAV, MP3, MP4, MOV No No No
Lean deps 3 runtime crates Varies Varies N/A
MCP Yes (12 tools) No No No
Streaming Yes No No No
Python JSON API Compatible No No Native
Language Rust Rust Rust Python

Documentation

Doc Description
ARCHITECTURE.md System design
SPEC.md Technical specification
TODO.md Roadmap
TROUBLESHOOTING.md Common failures and fixes
docs/CHANGELOG.md Version history
docs/MCP_SERVER.md MCP integration
docs/TEST_SUMMARY.md Test breakdown
docs/INDEX.md Documentation index

Links: GitHub Issues · crates.io · docs.rs

Examples

cargo run --example mcp_repair_json
cargo run --example mcp_multi_format

See examples/ and examples/README.md.

Roadmap

See TODO.md for planned work (WebP, FLAC, WebM, Protobuf, CLI polish, web/API, format-preserving repairs, and more).

License

Apache-2.0

Repository

If AnyRepair helps you, consider starring the repo on GitHub — it helps others find the project.

https://github.com/yingkitw/anyrepair