{"id":34110202,"url":"https://github.com/dvideby0/fast_json_repair","last_synced_at":"2026-03-17T20:13:51.522Z","repository":{"id":311907478,"uuid":"1045543920","full_name":"dvideby0/fast_json_repair","owner":"dvideby0","description":"Rust based JSON repair library","archived":false,"fork":false,"pushed_at":"2025-10-23T13:58:57.000Z","size":109,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-17T02:35:26.975Z","etag":null,"topics":["json","json-parser","llm-tools","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/fast-json-repair/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dvideby0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-27T10:45:19.000Z","updated_at":"2025-11-10T23:53:19.000Z","dependencies_parsed_at":"2025-08-27T20:00:03.561Z","dependency_job_id":"e57beb40-3271-4613-a521-53638841da40","html_url":"https://github.com/dvideby0/fast_json_repair","commit_stats":null,"previous_names":["dvideby0/fast_json_repair"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dvideby0/fast_json_repair","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvideby0%2Ffast_json_repair","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvideby0%2Ffast_json_repair/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvideby0%2Ffast_json_repair/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvideby0%2Ffast_json_repair/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvideby0","download_url":"https://codeload.github.com/dvideby0/fast_json_repair/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvideby0%2Ffast_json_repair/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30630317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","json-parser","llm-tools","python"],"created_at":"2025-12-14T18:47:39.578Z","updated_at":"2026-03-17T20:13:51.516Z","avatar_url":"https://github.com/dvideby0.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fast_json_repair\n\n[![PyPI version](https://badge.fury.io/py/fast-json-repair.svg)](https://pypi.org/project/fast-json-repair/)\n[![Python 3.11-3.14](https://img.shields.io/badge/python-3.11--3.14-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA high-performance JSON repair library for Python, powered by Rust. This is a drop-in replacement for [json_repair](https://github.com/mangiucugna/json_repair) with significant performance improvements.\n\n## 🙏 Attribution\n\nThis library is a **Rust port** of the excellent [json_repair](https://github.com/mangiucugna/json_repair) library created by [Stefano Baccianella](https://github.com/mangiucugna). The original Python implementation is a brilliant solution for fixing malformed JSON from Large Language Models (LLMs), and this port aims to bring the same functionality with improved performance.\n\n**All credit for the original concept, logic, and implementation goes to Stefano Baccianella.** This Rust port maintains API compatibility with the original library while leveraging Rust's performance benefits.\n\nIf you find this library useful, please also consider starring the [original json_repair repository](https://github.com/mangiucugna/json_repair).\n\n## Features\n\n- 📦 **Available on PyPI**: `pip install fast-json-repair`\n- 🚀 **Rust Performance**: Core repair logic implemented in Rust for maximum speed\n- 🔧 **Automatic Repair**: Fixes common JSON errors automatically\n- 🐍 **Python Compatible**: Works with Python 3.11-3.14\n- 🔄 **Drop-in Replacement**: Compatible API with the original json_repair library\n- ⚡ **Fast JSON Parsing**: Uses orjson for JSON parsing operations\n\n## Compatibility with Original json_repair\n\nThis is a **drop-in replacement** for the original `json_repair` library with the same API:\n\n**✅ Included:**\n- `repair_json()` - Main repair function with `return_objects`, `skip_json_loads`, `ensure_ascii`, `indent` parameters\n- `loads()` - Convenience function for loading broken JSON directly to Python objects\n- All repair capabilities: quotes, literals, commas, brackets, escape sequences, Unicode\n\n**❌ Not Included:**\n- File operations (`load()`, `from_file()`) - Use Python's built-in file handling + `repair_json()`\n- CLI tool - Library-only implementation\n- Streaming support - Not yet implemented\n\n**Key Differences:**\n- 🚀 **20x faster average**, up to 110x for large objects with long strings\n- 🔢 Unquoted numbers parsed as numbers (not strings)\n- 📦 Uses `orjson` for high-performance JSON operations\n\n## Installation\n\n### Quick Install\n\n```bash\npip install fast-json-repair\n```\n\n### Build from Source\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand build instructions\u003c/summary\u003e\n\n#### Prerequisites\n- Python 3.11-3.14\n- Rust toolchain (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`)\n- [uv](https://docs.astral.sh/uv/) (recommended) or pip\n\n#### Quick Start with uv (Recommended)\n\n```bash\n# Clone the repository\ngit clone https://github.com/dvideby0/fast_json_repair.git\ncd fast_json_repair\n\n# Run the automated setup script\n./setup.sh\n```\n\nThe setup script will:\n- ✅ Install `uv` and Rust if needed\n- ✅ Create a virtual environment (`.venv`)\n- ✅ Install all dependencies\n- ✅ Build the Rust extension\n- ✅ Verify the installation\n\n#### Manual Build Steps\n\n```bash\n# Clone the repository\ngit clone https://github.com/dvideby0/fast_json_repair.git\ncd fast_json_repair\n\n# Option 1: Using uv (fast!)\nuv venv\nsource .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\nuv sync\nmaturin develop --release\n\n# Option 2: Using pip\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\npip install maturin orjson\nmaturin develop --release\n```\n\n\u003c/details\u003e\n\n## Usage\n\n```python\nfrom fast_json_repair import repair_json, loads\n\n# Fix broken JSON\nbroken = \"{'name': 'John', 'age': 30}\"  # Single quotes\nfixed = repair_json(broken)\nprint(fixed)  # {\"age\":30,\"name\":\"John\"}\n\n# Parse directly to Python object\ndata = loads(\"{'key': 'value'}\")\nprint(data)  # {'key': 'value'}\n\n# Handle Unicode properly\ntext = \"{'message': '你好世界'}\"\nresult = repair_json(text, ensure_ascii=False)\nprint(result)  # {\"message\":\"你好世界\"}\n\n# Format with indentation\nformatted = repair_json(\"{'a': 1}\", indent=2)\n```\n\n## What It Repairs\n\nAutomatically fixes common JSON formatting issues:\n\n| Issue | Fix |\n|-------|-----|\n| Single quotes | → Double quotes |\n| Unquoted keys | → Quoted keys |\n| Python literals (True/False/None) | → JSON (true/false/null) |\n| Trailing commas | Removed |\n| Missing commas | Added |\n| Extra commas | Removed |\n| Unclosed brackets/braces | Auto-closed |\n| Invalid escape sequences | Fixed |\n| Unicode characters | Preserved or escaped (configurable) |\n\n## API Reference\n\n### `repair_json(json_string, **kwargs)`\n\nRepairs invalid JSON and returns valid JSON string.\n\n**Parameters:**\n- `json_string` (str): The potentially invalid JSON string to repair\n- `return_objects` (bool): If True, return parsed Python object instead of JSON string\n- `skip_json_loads` (bool): If True, skip initial validation for better performance\n- `ensure_ascii` (bool): If True, escape non-ASCII characters in output\n- `indent` (int): Number of spaces for indentation (None for compact output)\n\n**Returns:** \n- str or object: Repaired JSON string or parsed Python object\n\n### `loads(json_string, **kwargs)`\n\nRepairs and parses invalid JSON string to Python object.\n\n**Parameters:**\n- `json_string` (str): The potentially invalid JSON string to repair and parse\n- `**kwargs`: Additional arguments passed to repair_json\n\n**Returns:**\n- object: The parsed Python object\n\n## Performance\n\nThis Rust-based implementation provides significant performance improvements over the pure Python original.\n\n### Fast Path Optimization\n\nThe library automatically uses the fastest path when possible:\n\n**Fast Path (uses `orjson` for serialization):**\n- Valid JSON input\n- `ensure_ascii=False` \n- `indent` is either `None` (compact) or `2`\n\n**Fallback Path (uses stdlib `json`):**\n- Valid JSON input with `ensure_ascii=True`\n- Valid JSON input with `indent` values other than `None` or `2`\n\n**Repair Path (uses Rust implementation):**\n- Any invalid JSON that needs repair\n- Always respects `ensure_ascii` and `indent` settings\n\nFor maximum performance with valid JSON:\n```python\n# Fastest - uses orjson throughout\nresult = repair_json(valid_json, ensure_ascii=False, indent=2)\n\n# Slower - falls back to json.dumps for formatting\nresult = repair_json(valid_json, ensure_ascii=True)  # ASCII escaping\nresult = repair_json(valid_json, indent=4)  # Custom indentation\n```\n\n### Benchmark Results\n\nComprehensive comparison of fast_json_repair vs json_repair across 20 test cases (10 invalid JSON, 10 valid JSON) with both `ensure_ascii` settings:\n\n| Test Case | fast_json_repair (ms) | json_repair (ms) | Speedup |\n|-----------|----------------------|------------------|---------|\n| **Invalid JSON (needs repair)** | | | |\n| Simple quotes (ascii=T) | 0.007 | 0.032 | 🚀 4.7x |\n| Simple quotes (ascii=F) | 0.006 | 0.037 | 🚀 5.7x |\n| Medium nested (ascii=T) | 0.020 | 0.192 | 🚀 9.6x |\n| Medium nested (ascii=F) | 0.019 | 0.197 | 🚀 10.5x |\n| Large array 1000 (ascii=T) | 0.246 | 2.273 | 🚀 9.3x |\n| Large array 1000 (ascii=F) | 0.237 | 2.162 | 🚀 9.1x |\n| Deep nesting 50 (ascii=T) | 0.055 | 0.410 | 🚀 7.5x |\n| Deep nesting 50 (ascii=F) | 0.050 | 0.420 | 🚀 8.4x |\n| Large object 500 (ascii=T) | 0.404 | 27.339 | 🚀 **67.7x** |\n| Large object 500 (ascii=F) | 0.408 | 26.436 | 🚀 **64.8x** |\n| Complex mixed (ascii=T) | 0.033 | 0.408 | 🚀 12.2x |\n| Complex mixed (ascii=F) | 0.035 | 0.401 | 🚀 11.4x |\n| Very large 5000 (ascii=T) | 29.531 | 580.959 | 🚀 **19.7x** |\n| Very large 5000 (ascii=F) | 28.526 | 581.489 | 🚀 **20.4x** |\n| Long strings 10K (ascii=T) | 0.040 | 4.403 | 🚀 **110.2x** |\n| Long strings 10K (ascii=F) | 0.040 | 4.360 | 🚀 **108.7x** |\n| **Valid JSON (fast path)** | | | |\n| Small ASCII (ascii=T) | 0.003 | 0.004 | 🚀 1.3x |\n| Small ASCII (ascii=F) | 0.002 | 0.005 | 🚀 2.9x |\n| Nested structure (ascii=T) | 0.007 | 0.008 | 🚀 1.2x |\n| Nested structure (ascii=F) | 0.003 | 0.008 | 🚀 2.4x |\n| Large array 1000 (ascii=T) | 0.799 | 0.907 | 🚀 1.1x |\n| Large array 1000 (ascii=F) | 0.421 | 0.903 | 🚀 2.1x |\n| Large object 500 (ascii=T) | 0.506 | 0.590 | 🚀 1.2x |\n| Large object 500 (ascii=F) | 0.281 | 0.571 | 🚀 2.0x |\n\n**Overall: 19.7x faster** across all test cases\n\n**Key Insights:**\n- 🚀 = fast_json_repair is faster (all test cases)\n- **Invalid JSON repair**: 5-110x faster\n- **Valid JSON with ensure_ascii=False**: 2-3x faster (uses orjson fast path)\n- **Valid JSON with ensure_ascii=True**: 1.1-1.3x faster\n- **Best performance gains**: Long strings (110x), large objects (68x), very large arrays (20x)\n\n### Performance Advantages\n\n- **Large JSON documents**: 10-70x faster for documents with many keys/values\n- **Long strings**: Up to 110x faster for documents with large string values\n- **Very large arrays**: 20x faster for arrays with thousands of elements\n- **Deeply nested structures**: 7-10x faster with consistent performance\n- **Memory efficiency**: Lower memory footprint due to Rust's zero-cost abstractions and optimized allocations\n\nRun `python benchmark.py` to test performance on your system. See [PERFORMANCE.md](PERFORMANCE.md) for detailed analysis.\n\n## AWS Deployment\n\nWorks seamlessly on AWS with pre-built wheels for all architectures:\n- **x86_64** - Standard EC2 instances (t2, t3, m5, c5, etc.)\n- **ARM64/aarch64** - Graviton instances (t4g, m6g, c6g, etc.)\n\n```bash\n# Install on any AWS instance - pip auto-selects the correct wheel\npip install fast-json-repair\n```\n\nFor Lambda layers and cross-compilation, see [DEPLOYMENT.md](DEPLOYMENT.md).\n\n## Development\n\n### Quick Reference\n\n| Task | Command | VS Code Task |\n|------|---------|--------------|\n| **Setup** | `./setup.sh` | - |\n| **Build (debug)** | `maturin develop` | 🔧 Build: Development |\n| **Build (release)** | `maturin develop --release` | 🚀 Build: Development (Release) |\n| **Run tests** | `pytest tests/ -v` | 🧪 Test: Python (All) |\n| **Run benchmarks** | `python benchmark.py` | ⚡ Benchmark: Run Full Suite |\n| **Format code** | `cargo fmt \u0026\u0026 black . \u0026\u0026 isort .` | ✨ Format: All (Rust + Python) |\n| **Lint Rust** | `cargo clippy` | 🦀 Rust: Clippy |\n| **Lint Python** | `ruff check .` | 🐍 Python: Lint (Ruff) |\n| **Full check** | `maturin develop \u0026\u0026 pytest \u0026\u0026 python benchmark.py` | ✅ Full Check: Build + Test + Benchmark |\n\n### Quick Setup\n\n```bash\n# Automated setup (recommended)\n./setup.sh\n\n# Or manually with uv\nuv venv \u0026\u0026 source .venv/bin/activate\nuv sync\nmaturin develop\n```\n\n### VS Code Integration\n\nThis project includes a complete VS Code workspace configuration:\n\n**Getting Started:**\n1. Open the project folder in VS Code\n2. Install recommended extensions (you'll see a prompt)\n3. The Python interpreter will auto-detect `.venv`\n4. Press `Cmd+Shift+P` → \"Tasks: Run Task\" to see all available commands\n\n**Available Tasks:**\n- 🔧 **Build Tasks**: Debug build, release build, wheels, cross-platform builds\n- 🧪 **Test Tasks**: Run all tests, quick tests, coverage reports\n- ⚡ **Benchmark Tasks**: Full benchmarks, quick benchmarks, save results\n- 🦀 **Rust Tasks**: Check, clippy, format, clean\n- 🐍 **Python Tasks**: Format (black), sort imports (isort), lint (ruff)\n- 🚢 **Workflows**: Full check (build+test+benchmark), release prep, quality checks\n\n**Debugging:**\n- Press `F5` to debug Python tests\n- Set breakpoints in Python code\n- Use \"Debug: Select and Start Debugging\" for specific configs\n\n### Common Commands\n\nSee the Quick Reference table above for the most common tasks. Additional commands:\n\n```bash\n# Code quality\nblack .                # Format Python code\nisort .                # Sort Python imports\nruff check .           # Lint Python code\n\n# Cross-platform builds (requires zig)\nmaturin build --release --target x86_64-unknown-linux-gnu --zig\nmaturin build --release --target aarch64-unknown-linux-gnu --zig\nmaturin build --release --target universal2-apple-darwin\n```\n\n### Project Structure\n\n```\nfast_json_repair/\n├── src/\n│   └── lib.rs              # Rust implementation (core repair logic)\n├── python/\n│   └── fast_json_repair/\n│       └── __init__.py     # Python API wrapper\n├── tests/\n│   └── test_all.py         # Python test suite\n├── benchmark.py            # Performance benchmarks\n├── pyproject.toml          # Python package configuration\n├── Cargo.toml              # Rust package configuration\n└── .vscode/                # VS Code workspace settings (local)\n    ├── settings.json       # Python/Rust interpreter \u0026 formatting\n    ├── tasks.json          # Build/test/benchmark tasks\n    ├── launch.json         # Debug configurations\n    └── extensions.json     # Recommended extensions\n```\n\n### Typical Workflow\n\n1. **Make Changes** - Edit Rust (`src/`) or Python (`python/`) code\n2. **Rebuild** - `maturin develop` or VS Code task `🔧 Build: Development`\n3. **Test** - `pytest tests/ -v` or VS Code task `🧪 Test: Python (All)`\n4. **Benchmark** - `python benchmark.py` or VS Code task `⚡ Benchmark: Run Full Suite`\n5. **Release** - `maturin build --release` when ready to publish\n\n## License\n\nMIT License (same as original json_repair)\n\n## Credits \u0026 Acknowledgments\n\n### Original Author\n- **[Stefano Baccianella](https://github.com/mangiucugna)** - Creator of the original [json_repair](https://github.com/mangiucugna/json_repair) library\n  - Original concept and algorithm design\n  - Python implementation that this library is based on\n  - Comprehensive test cases and edge case handling\n\n### This Rust Port\n- Performance optimization through Rust implementation\n- Maintains full API compatibility with the original\n- Uses [PyO3](https://pyo3.rs/) for Python bindings\n- Uses [orjson](https://github.com/ijl/orjson) for fast JSON parsing\n\n### Special Thanks\nA huge thank you to Stefano Baccianella for creating json_repair and making it open source. This library wouldn't exist without the original brilliant implementation that has helped countless developers handle malformed JSON from LLMs.\n\nIf you appreciate this performance-focused port, please also show support for the [original json_repair project](https://github.com/mangiucugna/json_repair) that made it all possible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvideby0%2Ffast_json_repair","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvideby0%2Ffast_json_repair","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvideby0%2Ffast_json_repair/lists"}