AnyRepair
A Rust crate for repairing malformed structured data across multiple formats (JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff).
Quick Start
Installation
[]
= "0.2.1"
Basic Usage
use repair;
// Auto-detect format and repair
let malformed = r#"{"name": "John", age: 30,}"#;
let repaired = repair?;
println!; // {"name": "John", "age": 30}
CLI
# Install
# Auto-detect and repair
# Format-specific repair
# Show confidence score
# Batch process multiple files
# Stream large files
# Validation without repair
# Custom rules management
# Show supported formats
What's New
v0.2.1 - Latest Release
ποΈ KISS/DRY/SoC Refactoring
- Centralized format registry: single source of truth for formatβrepairer/validator mapping
- Unified CLI:
repair --format <fmt>replaces 8 per-format subcommands - Extracted
format_detectionmodule for clean separation of concerns - Removed dead code (
BaseRepairertrait, standaloneapply_strategies) - ~400 lines of duplicated code eliminated
π§ 8 Format Support
- JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff/Unified Diff
- Auto-detection from malformed content
- Format-specific validation and repair strategies
π Python-Compatible API
- Drop-in compatible with Python's
jsonrepairlibrary jsonrepair()function andJsonRepairclass API
π MCP Server Integration
- Native Claude Desktop integration via MCP
- 10 MCP tools for all 8 formats plus auto-detect and validate
β‘ Performance & Quality
- 280+ test cases with 100% pass rate
- 99.6% improvement from regex caching
- Streaming support for files larger than RAM
- Zero compilation warnings
See CHANGELOG.md for complete 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 issues, missing colons
- Markdown: Malformed headers, broken links
- XML/TOML/CSV/INI/Diff: Format-specific repairs
Key Features:
- β Auto-detects format from damaged content
- β Multi-format support (8 formats)
- β High performance (regex caching, optimized binaries)
- β MCP server for Claude integration
- β Streaming support for large files
- β 280+ tests, 100% pass rate
Usage Examples
Multi-Format Auto-Detection
use repair;
// JSON - auto-detected and repaired
let json = repair?;
// Output: {"key": "value"}
// YAML - auto-detected and repaired
let yaml = repair?;
// Markdown - auto-detected and repaired
let markdown = repair?;
// Diff - auto-detected and repaired
let diff = repair?;
Python-Compatible JSON API
use ;
// Function-based API (like Python's jsonrepair)
let repaired = jsonrepair?;
// Class-based API (like Python's JsonRepair class)
let mut jr = new;
let repaired1 = jr.jsonrepair?;
let repaired2 = jr.jsonrepair?;
Format-Specific Repairers
use ;
// Via registry (recommended)
let mut repairer = create_repairer?;
let repaired = repairer.repair?;
let confidence = repairer.confidence;
// Shorthand
let repaired = repair_with_format?;
// Direct struct usage still works
use JsonRepairer;
let mut json_repairer = new;
let repaired = json_repairer.repair?;
Streaming Large Files
use StreamingRepair;
use File;
use BufReader;
let input = new;
let mut output = create?;
// Configure buffer size (default 8192 bytes)
let processor = with_buffer_size;
// Process with automatic format detection
processor.process?;
// Or specify format explicitly
processor.process?;
Batch Processing
use BatchProcessor;
let processor = new;
// Process directory with options
let results = processor.process_directory?;
// Get per-file results
for result in results
// Get analytics
let analytics = processor.get_analytics;
println!;
MCP Server Integration
The MCP server provides seamless integration with Claude Desktop:
# Install and run MCP server
Configure in claude_desktop_config.json:
Available MCP Tools:
repair- Auto-detect and repair any formatrepair_json,repair_yaml,repair_markdown,repair_xmlrepair_toml,repair_csv,repair_ini,repair_diffvalidate- Validate content without repair
Usage in Claude:
Please repair this JSON: {"name": "John", age: 30,}
(Claude will use the anyrepair MCP tool to fix it)
See MCP_SERVER.md for complete documentation.
Supported Formats
| Format | Common Issues Fixed |
|---|---|
| JSON | Missing quotes, trailing commas, malformed numbers, boolean/null values |
| YAML | Indentation, missing colons, list formatting, document separators |
| Markdown | Headers, code blocks, lists, tables, links, images |
| XML | Unclosed tags, malformed attributes, missing quotes, entity encoding |
| TOML | Missing quotes, malformed arrays, table headers, dates |
| CSV | Unquoted strings, malformed quotes, extra/missing commas |
| INI | Malformed sections, missing equals signs, unquoted values |
| Diff | Missing hunk headers, incorrect line prefixes, malformed ranges |
Advanced Features
Custom Rules
# Add custom repair rule via CLI
# List all rules
# Enable/disable rules
# Remove a rule
Configuration file (anyrepair.toml):
# Custom rules configuration
[[]]
= "fix_trailing_comma"
= "json"
= ",\\s*}"
= "}"
= 95
[[]]
= "fix_js_comments"
= "json"
= "//.*\\n"
= ""
= 80
Performance
- Regex Caching: 99.6% performance improvement over uncached operations
- Optimized Binaries: 1.5 MB release builds (94% size reduction)
- Streaming: Process files larger than available RAM using configurable buffers
- Lazy Evaluation: Skip unnecessary strategies for faster repairs
Build Profiles:
# Standard release (size-optimized)
# Distribution profile (maximum optimization)
Testing
- 280+ test cases with 100% pass rate
- 190 library tests (incl. 73 MCP server tests)
- 35 diff tests
- 26 streaming tests
- 18 complex damage tests
- 18 complex streaming tests
- 36 fuzz tests
- 18 damage scenarios
- 17 integration tests
- 15 CLI tests
- 2 doctests
- Fuzz testing using proptest for robustness
- Integration tests for end-to-end workflows
See TEST_SUMMARY.md for details.
Comparison
| Feature | AnyRepair | json-repair-rs | json5 | Python jsonrepair |
|---|---|---|---|---|
| Multi-format | β 8 formats | β JSON only | β JSON only | β JSON only |
| Auto-detection | β Smart detection | β | β | β |
| MCP integration | β Native | β | β | β |
| Streaming | β Large file support | β | β | β |
| Custom rules | β CLI + API | β | β | β |
| Python API | β Compatible | β | β | β Native |
| Language | Rust | Rust | Rust | Python |
| Binary size | 1.5 MB | ~500 KB | ~200 KB | N/A |
Why AnyRepair?
- Most comprehensive format support (8 formats vs JSON-only alternatives)
- Only Rust crate with Python-compatible API and MCP integration
- Battle-tested with 280+ tests covering real-world failures
- Zero compilation warnings
Documentation
- ARCHITECTURE.md - System design and architecture
- MCP_SERVER.md - MCP server integration guide
- TEST_SUMMARY.md - Test coverage details
- CHANGELOG.md - Version history and changes
- INDEX.md - Complete documentation index
- STREAMING_FEATURE.md - Streaming support details
- BUILD_OPTIMIZATION.md - Build optimization guide
Quick Links
- Report Issues: GitHub Issues
- Contributing: See CONTRIBUTING.md (if available)
- Changelog: CHANGELOG.md
- API Docs: docs.rs
Examples
See the examples/ directory for:
- mcp_repair_json.rs - MCP JSON repair usage
- mcp_multi_format.rs - Multi-format MCP repair
- mcp_server_usage.rs - MCP server setup and usage
Run examples:
Roadmap
See TODO.md for planned features and improvement areas. Highlights include:
- Additional format support (Properties, .env, Protobuf)
- CLI enhancements (diff preview, dry-run, colored output)
- Web interface and REST API
- Language bindings (Python, Node.js, Go)
- Format-preserving repairs, repair explanations
License
Apache-2.0
Repository
β If you find AnyRepair useful, please consider starring the repo on GitHub! It helps others discover the project and motivates continued development.
π¬ Feedback welcome! Share your experience, suggestions, or report issues via GitHub Issues, or leave a review on crates.io.