AnyRepair
A Rust crate for repairing malformed structured data across 10 formats (JSON, YAML, Markdown, XML, TOML, CSV, INI, Diff, Java properties, and .env).
Quick Start
Installation
[]
= "0.2.9"
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
# Preview changes as a diff (no output written)
# Dry-run without writing output
# Machine-readable JSON output for CI
# Require minimum confidence (exit with error if below threshold)
# Show which repair strategies were applied
# Generate shell completions
# Batch process multiple files
# Stream large files
# Validation without repair
Docker
# MCP server
What's New
v0.2.9 — Current
detect_format_with_confidence— format detection returns a confidence score (DetectionResult)- Docker image — multi-stage
Dockerfilefor CLI and MCP binaries - MCP version —
anyrepair-mcpreportsCARGO_PKG_VERSION(no more stale hardcoded version) - Integration tests for smart quotes, boolean variants, and prose extraction
- 432 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
strictfeature forserde_json-backed JSON validation - Golden master + properties/env integration tests
v0.2.7
- Auto-detect properties & env —
detect_format()now recognizes.propertiesand.envfiles - Heuristic validator fixes — XML / CSV edge cases
- Criterion benchmarks — All 10 formats + format detection + large-document throughput
v0.2.6
- Minimal dependencies and
json_utilwithout serde - Heuristic validators for XML, TOML, CSV, and YAML
v0.2.0–0.2.5 (highlights)
- Properties/
.envformats, centralized registry, Python-compatiblejsonrepair(), 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 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
- Python-compatible JSON API
- Optional
strictfeature for fullserde_jsonparser validation - 415 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:
Usage Examples
Multi-Format Auto-Detection
use repair;
let json = repair?;
let yaml = repair?;
let markdown = repair?;
Explicit key-value formats
use repair_with_format;
let props = repair_with_format?;
let env = repair_with_format?;
Python-Compatible JSON API
use ;
let repaired = jsonrepair?;
let mut jr = new;
let repaired = jr.jsonrepair?;
Format-Specific Repairers
use ;
let mut repairer = create_repairer?;
let repaired = repairer.repair?;
let confidence = repairer.confidence;
let repaired = repair_with_format?;
Streaming Large Files
use StreamingRepair;
use File;
use BufReader;
let input = new;
let mut output = create?;
let processor = with_buffer_size;
processor.process?;
MCP Server Integration
claude_desktop_config.json:
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 |
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
Testing
| Suite | Tests |
|---|---|
| Library / modules | 177 |
| Completions / CLI extras | 19 |
| CLI | 15 |
| Integration | 21 |
| Diff | 35 |
| Fuzz (proptest) | 34 |
| Streaming | 26 |
| Properties/env | 25 |
| Golden master | 26 |
| Damage + complex damage + complex streaming | 54 |
| Total | 432 |
See TEST_SUMMARY.md for more detail.
Comparison
| Feature | AnyRepair | json-repair-rs | json5 | Python jsonrepair |
|---|---|---|---|---|
| Multi-format | 10 formats | JSON only | JSON only | JSON only |
| Auto-detection | 10 formats | 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
See examples/ and examples/README.md.
Roadmap
See TODO.md for planned work (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.