fast-json-repair


Namefast-json-repair JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryHigh-performance JSON repair library using Rust
upload_time2025-08-27 14:25:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT
keywords json repair parser rust performance llm ai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fast_json_repair

[![PyPI version](https://badge.fury.io/py/fast-json-repair.svg)](https://pypi.org/project/fast-json-repair/)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A 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.

## πŸ™ Attribution

This 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.

**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.

If you find this library useful, please also consider starring the [original json_repair repository](https://github.com/mangiucugna/json_repair).

## Features

- πŸ“¦ **Available on PyPI**: `pip install fast-json-repair`
- πŸš€ **Rust Performance**: Core repair logic implemented in Rust for maximum speed
- πŸ”§ **Automatic Repair**: Fixes common JSON errors automatically
- 🐍 **Python Compatible**: Works with Python 3.11+
- πŸ”„ **Drop-in Replacement**: Compatible API with the original json_repair library
- ⚑ **Fast JSON Parsing**: Uses orjson for JSON parsing operations

## Compatibility with Original json_repair

### βœ… Included Features
- **`repair_json()`** - Main repair function with all parameters:
  - `return_objects` - Return parsed Python objects instead of JSON string
  - `skip_json_loads` - Skip initial JSON validation for better performance  
  - `ensure_ascii` - Control Unicode escaping in output
  - `indent` - Format output with indentation
- **`loads()`** - Convenience function for loading broken JSON directly to Python objects
- **All repair capabilities**:
  - Single quotes β†’ double quotes
  - Unquoted keys β†’ quoted keys
  - Python literals (True/False/None) β†’ JSON literals (true/false/null)
  - Trailing commas removal
  - Missing commas addition
  - Auto-closing unclosed brackets/braces
  - Escape sequence handling
  - Unicode support

### ❌ Not Included (By Design)
- **File operations** (`load()`, `from_file()`) - Use Python's built-in file handling + repair_json()
- **CLI tool** - This is a library-only implementation
- **Streaming support** (`stream_stable` parameter) - Not yet implemented
- **Custom JSON encoder parameters** - Uses orjson's optimized defaults

### πŸ”„ Differences
- **Number parsing**: Unquoted numbers are parsed as numbers (not strings)
- **Performance**: 5x faster average, up to 15x for large objects
- **Dependencies**: Requires `orjson` instead of standard `json` library

## Installation

### Quick Install

```bash
pip install fast-json-repair
```

### Install from GitHub Releases

Download pre-built wheels from the [Releases page](https://github.com/dvideby0/fast_json_repair/releases):

```bash
# For macOS (Intel)
pip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl

# For macOS (Apple Silicon)  
pip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-macosx_11_0_arm64.whl

# For Linux x86_64
pip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-manylinux_2_17_x86_64.whl

# For Linux ARM64 (AWS Graviton)
pip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-manylinux_2_17_aarch64.whl

# For Windows
pip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-win_amd64.whl
```

### Build from Source

<details>
<summary>Click to expand build instructions</summary>

#### Prerequisites
- Python 3.11 or higher
- Rust toolchain (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`)

#### Build Steps

```bash
# Clone the repository
git clone https://github.com/dvideby0/fast_json_repair.git
cd fast_json_repair

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install build dependencies
pip install maturin orjson

# Build and install the package
maturin develop --release
```

</details>

## Usage

```python
from fast_json_repair import repair_json, loads

# Fix broken JSON
broken = "{'name': 'John', 'age': 30}"  # Single quotes
fixed = repair_json(broken)
print(fixed)  # {"age":30,"name":"John"}

# Parse directly to Python object
data = loads("{'key': 'value'}")
print(data)  # {'key': 'value'}

# Handle Unicode properly
text = "{'message': 'δ½ ε₯½δΈ–η•Œ'}"
result = repair_json(text, ensure_ascii=False)
print(result)  # {"message":"δ½ ε₯½δΈ–η•Œ"}

# Format with indentation
formatted = repair_json("{'a': 1}", indent=2)
```

## What it repairs

- **Single quotes** β†’ Double quotes
- **Unquoted keys** β†’ Quoted keys
- **Python literals** → JSON equivalents (True→true, False→false, None→null)
- **Trailing commas** β†’ Removed
- **Missing commas** β†’ Added
- **Extra commas** β†’ Removed
- **Unclosed brackets/braces** β†’ Auto-closed
- **Escape sequences** β†’ Properly handled
- **Unicode characters** β†’ Preserved or escaped based on settings

## API Reference

### `repair_json(json_string, **kwargs)`

Repairs invalid JSON and returns valid JSON string.

**Parameters:**
- `json_string` (str): The potentially invalid JSON string to repair
- `return_objects` (bool): If True, return parsed Python object instead of JSON string
- `skip_json_loads` (bool): If True, skip initial validation for better performance
- `ensure_ascii` (bool): If True, escape non-ASCII characters in output
- `indent` (int): Number of spaces for indentation (None for compact output)

**Returns:** 
- str or object: Repaired JSON string or parsed Python object

### `loads(json_string, **kwargs)`

Repairs and parses invalid JSON string to Python object.

**Parameters:**
- `json_string` (str): The potentially invalid JSON string to repair and parse
- `**kwargs`: Additional arguments passed to repair_json

**Returns:**
- object: The parsed Python object

## Performance

This Rust-based implementation provides significant performance improvements over the pure Python original.

### Fast Path Optimization

The library automatically uses the fastest path when possible:

**Fast Path (uses `orjson` for serialization):**
- Valid JSON input
- `ensure_ascii=False` 
- `indent` is either `None` (compact) or `2`

**Fallback Path (uses stdlib `json`):**
- Valid JSON input with `ensure_ascii=True`
- Valid JSON input with `indent` values other than `None` or `2`

**Repair Path (uses Rust implementation):**
- Any invalid JSON that needs repair
- Always respects `ensure_ascii` and `indent` settings

For maximum performance with valid JSON:
```python
# Fastest - uses orjson throughout
result = repair_json(valid_json, ensure_ascii=False, indent=2)

# Slower - falls back to json.dumps for formatting
result = repair_json(valid_json, ensure_ascii=True)  # ASCII escaping
result = repair_json(valid_json, indent=4)  # Custom indentation
```

### Benchmark Results

Comprehensive comparison of fast_json_repair vs json_repair across 20 test cases (10 invalid JSON, 10 valid JSON) with both `ensure_ascii` settings:

| Test Case | fast_json_repair (ms) | json_repair (ms) | Speedup |
|-----------|----------------------|------------------|---------|
| **Invalid JSON (needs repair)** | | | |
| Simple quotes (ascii=T) | 0.018 | 0.030 | πŸš€ 1.7x |
| Simple quotes (ascii=F) | 0.018 | 0.029 | πŸš€ 1.6x |
| Medium nested (ascii=T) | 0.064 | 0.178 | πŸš€ 2.8x |
| Medium nested (ascii=F) | 0.062 | 0.184 | πŸš€ 3.0x |
| Large array 1000 (ascii=T) | 1.093 | 2.154 | πŸš€ 2.0x |
| Large array 1000 (ascii=F) | 1.051 | 2.160 | πŸš€ 2.1x |
| Deep nesting 50 (ascii=T) | 0.139 | 0.372 | πŸš€ 2.7x |
| Deep nesting 50 (ascii=F) | 0.133 | 0.368 | πŸš€ 2.8x |
| Large object 500 (ascii=T) | 1.717 | 28.194 | πŸš€ **16.4x** |
| Large object 500 (ascii=F) | 1.702 | 28.570 | πŸš€ **16.8x** |
| Complex mixed (ascii=T) | 0.105 | 0.365 | πŸš€ 3.5x |
| Complex mixed (ascii=F) | 0.102 | 0.366 | πŸš€ 3.6x |
| Very large 5000 (ascii=T) | 103.896 | 509.603 | πŸš€ **4.9x** |
| Very large 5000 (ascii=F) | 102.053 | 506.772 | πŸš€ **5.0x** |
| Long strings 10K (ascii=T) | 0.568 | 3.399 | πŸš€ **6.0x** |
| Long strings 10K (ascii=F) | 0.576 | 3.430 | πŸš€ **6.0x** |
| **Valid JSON (fast path)** | | | |
| Small ASCII (ascii=T) | 0.003 | 0.004 | πŸš€ 1.4x |
| Small ASCII (ascii=F) | 0.002 | 0.005 | πŸš€ 2.8x |
| Nested structure (ascii=T) | 0.006 | 0.008 | πŸš€ 1.3x |
| Nested structure (ascii=F) | 0.003 | 0.010 | πŸš€ 3.1x |
| Large array 1000 (ascii=T) | 0.747 | 0.887 | πŸš€ 1.2x |
| Large array 1000 (ascii=F) | 0.431 | 0.938 | πŸš€ 2.2x |
| Large object 500 (ascii=T) | 0.518 | 0.558 | πŸš€ 1.1x |
| Large object 500 (ascii=F) | 0.277 | 0.555 | πŸš€ 2.0x |

**Overall: 5.1x faster** across all test cases

**Key Insights:**
- πŸš€ = fast_json_repair is faster (all test cases)
- **Invalid JSON repair**: 2-17x faster
- **Valid JSON with ensure_ascii=False**: 2-3x faster (uses orjson fast path)
- **Valid JSON with ensure_ascii=True**: 1.1-1.4x faster
- **Best performance gains**: Large objects (16x), long strings (6x), complex structures (5x)

### Performance Advantages

- **Large JSON documents**: 5-15x faster for documents with many keys/values
- **Deeply nested structures**: 2-3x faster with consistent performance
- **Documents with many errors**: Scales better with number of repairs needed
- **Memory efficiency**: Lower memory footprint due to Rust's zero-cost abstractions

Run `python benchmark.py` to test performance on your system.

## Differences from original json_repair

- Core repair logic implemented in Rust for performance
- Uses orjson instead of standard json library
- Numbers in unquoted values are parsed as numbers (not strings)
- Focused on string repair only (no file operations in core library)

## AWS Deployment

This library works perfectly on AWS Linux systems. Pre-built wheels are available for:
- **x86_64** (standard EC2 instances like t2, t3, m5, c5)
- **ARM64/aarch64** (Graviton instances like t4g, m6g, c6g)

### Quick Deploy to AWS

```bash
# Simply install from PyPI (works on all architectures)
pip install fast-json-repair

# The correct wheel for your architecture will be automatically selected:
# - x86_64 instances: manylinux_2_17_x86_64 wheel
# - ARM64/Graviton instances: manylinux_2_17_aarch64 wheel
```

### Building Linux Wheels (Cross-compilation from macOS)

```bash
# Install build tools
cargo install cargo-zigbuild
brew install zig

# Add Linux targets
rustup target add x86_64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-gnu

# Build Linux x86_64 wheel
maturin build --release --target x86_64-unknown-linux-gnu --zig

# Build Linux ARM64 wheel (for AWS Graviton)
maturin build --release --target aarch64-unknown-linux-gnu --zig
```

### AWS Lambda Deployment

Create a Lambda layer:
```bash
mkdir -p lambda-layer/python
pip install -t lambda-layer/python/ target/wheels/fast_json_repair-*.whl orjson
cd lambda-layer && zip -r fast_json_repair_layer.zip python
```

See [DEPLOYMENT.md](DEPLOYMENT.md) for detailed deployment instructions.

## Development

```bash
# Run tests
python test_repair.py

# Build for current platform
maturin develop

# Build release wheels
maturin build --release
```

## License

MIT License (same as original json_repair)

## Credits & Acknowledgments

### Original Author
- **[Stefano Baccianella](https://github.com/mangiucugna)** - Creator of the original [json_repair](https://github.com/mangiucugna/json_repair) library
  - Original concept and algorithm design
  - Python implementation that this library is based on
  - Comprehensive test cases and edge case handling

### This Rust Port
- Performance optimization through Rust implementation
- Maintains full API compatibility with the original
- Uses [PyO3](https://pyo3.rs/) for Python bindings
- Uses [orjson](https://github.com/ijl/orjson) for fast JSON parsing

### Special Thanks
A 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.

If 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.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fast-json-repair",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "json, repair, parser, rust, performance, llm, ai",
    "author": null,
    "author_email": "dvideby0 <>",
    "download_url": "https://files.pythonhosted.org/packages/1d/1a/6586adac9fda8648f217ec0aa4f3f62ec6f516d3f10a918f9369d8c65f46/fast_json_repair-0.1.3.tar.gz",
    "platform": null,
    "description": "# 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+](https://img.shields.io/badge/python-3.11+-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## \ud83d\ude4f 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- \ud83d\udce6 **Available on PyPI**: `pip install fast-json-repair`\n- \ud83d\ude80 **Rust Performance**: Core repair logic implemented in Rust for maximum speed\n- \ud83d\udd27 **Automatic Repair**: Fixes common JSON errors automatically\n- \ud83d\udc0d **Python Compatible**: Works with Python 3.11+\n- \ud83d\udd04 **Drop-in Replacement**: Compatible API with the original json_repair library\n- \u26a1 **Fast JSON Parsing**: Uses orjson for JSON parsing operations\n\n## Compatibility with Original json_repair\n\n### \u2705 Included Features\n- **`repair_json()`** - Main repair function with all parameters:\n  - `return_objects` - Return parsed Python objects instead of JSON string\n  - `skip_json_loads` - Skip initial JSON validation for better performance  \n  - `ensure_ascii` - Control Unicode escaping in output\n  - `indent` - Format output with indentation\n- **`loads()`** - Convenience function for loading broken JSON directly to Python objects\n- **All repair capabilities**:\n  - Single quotes \u2192 double quotes\n  - Unquoted keys \u2192 quoted keys\n  - Python literals (True/False/None) \u2192 JSON literals (true/false/null)\n  - Trailing commas removal\n  - Missing commas addition\n  - Auto-closing unclosed brackets/braces\n  - Escape sequence handling\n  - Unicode support\n\n### \u274c Not Included (By Design)\n- **File operations** (`load()`, `from_file()`) - Use Python's built-in file handling + repair_json()\n- **CLI tool** - This is a library-only implementation\n- **Streaming support** (`stream_stable` parameter) - Not yet implemented\n- **Custom JSON encoder parameters** - Uses orjson's optimized defaults\n\n### \ud83d\udd04 Differences\n- **Number parsing**: Unquoted numbers are parsed as numbers (not strings)\n- **Performance**: 5x faster average, up to 15x for large objects\n- **Dependencies**: Requires `orjson` instead of standard `json` library\n\n## Installation\n\n### Quick Install\n\n```bash\npip install fast-json-repair\n```\n\n### Install from GitHub Releases\n\nDownload pre-built wheels from the [Releases page](https://github.com/dvideby0/fast_json_repair/releases):\n\n```bash\n# For macOS (Intel)\npip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl\n\n# For macOS (Apple Silicon)  \npip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-macosx_11_0_arm64.whl\n\n# For Linux x86_64\npip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-manylinux_2_17_x86_64.whl\n\n# For Linux ARM64 (AWS Graviton)\npip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-manylinux_2_17_aarch64.whl\n\n# For Windows\npip install https://github.com/dvideby0/fast_json_repair/releases/download/v0.1.2/fast_json_repair-0.1.2-cp311-abi3-win_amd64.whl\n```\n\n### Build from Source\n\n<details>\n<summary>Click to expand build instructions</summary>\n\n#### Prerequisites\n- Python 3.11 or higher\n- Rust toolchain (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`)\n\n#### 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# Create a virtual environment (recommended)\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n\n# Install build dependencies\npip install maturin orjson\n\n# Build and install the package\nmaturin develop --release\n```\n\n</details>\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': '\u4f60\u597d\u4e16\u754c'}\"\nresult = repair_json(text, ensure_ascii=False)\nprint(result)  # {\"message\":\"\u4f60\u597d\u4e16\u754c\"}\n\n# Format with indentation\nformatted = repair_json(\"{'a': 1}\", indent=2)\n```\n\n## What it repairs\n\n- **Single quotes** \u2192 Double quotes\n- **Unquoted keys** \u2192 Quoted keys\n- **Python literals** \u2192 JSON equivalents (True\u2192true, False\u2192false, None\u2192null)\n- **Trailing commas** \u2192 Removed\n- **Missing commas** \u2192 Added\n- **Extra commas** \u2192 Removed\n- **Unclosed brackets/braces** \u2192 Auto-closed\n- **Escape sequences** \u2192 Properly handled\n- **Unicode characters** \u2192 Preserved or escaped based on settings\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.018 | 0.030 | \ud83d\ude80 1.7x |\n| Simple quotes (ascii=F) | 0.018 | 0.029 | \ud83d\ude80 1.6x |\n| Medium nested (ascii=T) | 0.064 | 0.178 | \ud83d\ude80 2.8x |\n| Medium nested (ascii=F) | 0.062 | 0.184 | \ud83d\ude80 3.0x |\n| Large array 1000 (ascii=T) | 1.093 | 2.154 | \ud83d\ude80 2.0x |\n| Large array 1000 (ascii=F) | 1.051 | 2.160 | \ud83d\ude80 2.1x |\n| Deep nesting 50 (ascii=T) | 0.139 | 0.372 | \ud83d\ude80 2.7x |\n| Deep nesting 50 (ascii=F) | 0.133 | 0.368 | \ud83d\ude80 2.8x |\n| Large object 500 (ascii=T) | 1.717 | 28.194 | \ud83d\ude80 **16.4x** |\n| Large object 500 (ascii=F) | 1.702 | 28.570 | \ud83d\ude80 **16.8x** |\n| Complex mixed (ascii=T) | 0.105 | 0.365 | \ud83d\ude80 3.5x |\n| Complex mixed (ascii=F) | 0.102 | 0.366 | \ud83d\ude80 3.6x |\n| Very large 5000 (ascii=T) | 103.896 | 509.603 | \ud83d\ude80 **4.9x** |\n| Very large 5000 (ascii=F) | 102.053 | 506.772 | \ud83d\ude80 **5.0x** |\n| Long strings 10K (ascii=T) | 0.568 | 3.399 | \ud83d\ude80 **6.0x** |\n| Long strings 10K (ascii=F) | 0.576 | 3.430 | \ud83d\ude80 **6.0x** |\n| **Valid JSON (fast path)** | | | |\n| Small ASCII (ascii=T) | 0.003 | 0.004 | \ud83d\ude80 1.4x |\n| Small ASCII (ascii=F) | 0.002 | 0.005 | \ud83d\ude80 2.8x |\n| Nested structure (ascii=T) | 0.006 | 0.008 | \ud83d\ude80 1.3x |\n| Nested structure (ascii=F) | 0.003 | 0.010 | \ud83d\ude80 3.1x |\n| Large array 1000 (ascii=T) | 0.747 | 0.887 | \ud83d\ude80 1.2x |\n| Large array 1000 (ascii=F) | 0.431 | 0.938 | \ud83d\ude80 2.2x |\n| Large object 500 (ascii=T) | 0.518 | 0.558 | \ud83d\ude80 1.1x |\n| Large object 500 (ascii=F) | 0.277 | 0.555 | \ud83d\ude80 2.0x |\n\n**Overall: 5.1x faster** across all test cases\n\n**Key Insights:**\n- \ud83d\ude80 = fast_json_repair is faster (all test cases)\n- **Invalid JSON repair**: 2-17x 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.4x faster\n- **Best performance gains**: Large objects (16x), long strings (6x), complex structures (5x)\n\n### Performance Advantages\n\n- **Large JSON documents**: 5-15x faster for documents with many keys/values\n- **Deeply nested structures**: 2-3x faster with consistent performance\n- **Documents with many errors**: Scales better with number of repairs needed\n- **Memory efficiency**: Lower memory footprint due to Rust's zero-cost abstractions\n\nRun `python benchmark.py` to test performance on your system.\n\n## Differences from original json_repair\n\n- Core repair logic implemented in Rust for performance\n- Uses orjson instead of standard json library\n- Numbers in unquoted values are parsed as numbers (not strings)\n- Focused on string repair only (no file operations in core library)\n\n## AWS Deployment\n\nThis library works perfectly on AWS Linux systems. Pre-built wheels are available for:\n- **x86_64** (standard EC2 instances like t2, t3, m5, c5)\n- **ARM64/aarch64** (Graviton instances like t4g, m6g, c6g)\n\n### Quick Deploy to AWS\n\n```bash\n# Simply install from PyPI (works on all architectures)\npip install fast-json-repair\n\n# The correct wheel for your architecture will be automatically selected:\n# - x86_64 instances: manylinux_2_17_x86_64 wheel\n# - ARM64/Graviton instances: manylinux_2_17_aarch64 wheel\n```\n\n### Building Linux Wheels (Cross-compilation from macOS)\n\n```bash\n# Install build tools\ncargo install cargo-zigbuild\nbrew install zig\n\n# Add Linux targets\nrustup target add x86_64-unknown-linux-gnu\nrustup target add aarch64-unknown-linux-gnu\n\n# Build Linux x86_64 wheel\nmaturin build --release --target x86_64-unknown-linux-gnu --zig\n\n# Build Linux ARM64 wheel (for AWS Graviton)\nmaturin build --release --target aarch64-unknown-linux-gnu --zig\n```\n\n### AWS Lambda Deployment\n\nCreate a Lambda layer:\n```bash\nmkdir -p lambda-layer/python\npip install -t lambda-layer/python/ target/wheels/fast_json_repair-*.whl orjson\ncd lambda-layer && zip -r fast_json_repair_layer.zip python\n```\n\nSee [DEPLOYMENT.md](DEPLOYMENT.md) for detailed deployment instructions.\n\n## Development\n\n```bash\n# Run tests\npython test_repair.py\n\n# Build for current platform\nmaturin develop\n\n# Build release wheels\nmaturin build --release\n```\n\n## License\n\nMIT License (same as original json_repair)\n\n## Credits & 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\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "High-performance JSON repair library using Rust",
    "version": "0.1.3",
    "project_urls": {
        "Documentation": "https://github.com/dvideby0/fast_json_repair#readme",
        "Homepage": "https://github.com/dvideby0/fast_json_repair",
        "Issues": "https://github.com/dvideby0/fast_json_repair/issues",
        "Repository": "https://github.com/dvideby0/fast_json_repair"
    },
    "split_keywords": [
        "json",
        " repair",
        " parser",
        " rust",
        " performance",
        " llm",
        " ai"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f86d9588e946447c7a735edc536b1a2d42da9246197495e01e7c57a7dcf01914",
                "md5": "4af529e9d6828475f8306d3515e3fa7c",
                "sha256": "c5439423ac5ecc01a47e9715664ca58cced8357bc6be5dab6a0307e158ce462d"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "has_sig": false,
            "md5_digest": "4af529e9d6828475f8306d3515e3fa7c",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.11",
            "size": 431363,
            "upload_time": "2025-08-27T14:25:19",
            "upload_time_iso_8601": "2025-08-27T14:25:19.505074Z",
            "url": "https://files.pythonhosted.org/packages/f8/6d/9588e946447c7a735edc536b1a2d42da9246197495e01e7c57a7dcf01914/fast_json_repair-0.1.3-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ca37c6a8fefb83c33d1e9a2d682a262020f0ce009ad690fa8737334ef9bff330",
                "md5": "29170d1c709d3566c73fff9456835fa6",
                "sha256": "3f9650836b7d6d97ccd03d79b22156bbd484c8d946b0fba666d5b9e1df8b3465"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "29170d1c709d3566c73fff9456835fa6",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.11",
            "size": 226533,
            "upload_time": "2025-08-27T14:25:21",
            "upload_time_iso_8601": "2025-08-27T14:25:21.024584Z",
            "url": "https://files.pythonhosted.org/packages/ca/37/c6a8fefb83c33d1e9a2d682a262020f0ce009ad690fa8737334ef9bff330/fast_json_repair-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0f75d90cdc27f7f813b956a8bd1eda0c607f5a73b2b6f791b2a934c5610c3892",
                "md5": "f5b9156eb6794fac9191f8488e7d1689",
                "sha256": "a6b3b75b8c7c80eb673c61bfab0b9115ae477fc314e8759824a026055cd8df25"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3-cp311-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "f5b9156eb6794fac9191f8488e7d1689",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.11",
            "size": 212582,
            "upload_time": "2025-08-27T14:25:22",
            "upload_time_iso_8601": "2025-08-27T14:25:22.376524Z",
            "url": "https://files.pythonhosted.org/packages/0f/75/d90cdc27f7f813b956a8bd1eda0c607f5a73b2b6f791b2a934c5610c3892/fast_json_repair-0.1.3-cp311-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "54b42b4e742c4409191c155d81ec6efc8fc828f9629e56e0ac350eb467534207",
                "md5": "1fd0383f1d1cd0c6634b335c05e0f465",
                "sha256": "d8c6f91aef7c287fc697a6e79202befeabadb2e10f841f7df4b8588d06ba8f0f"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "1fd0383f1d1cd0c6634b335c05e0f465",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.11",
            "size": 233342,
            "upload_time": "2025-08-27T14:25:23",
            "upload_time_iso_8601": "2025-08-27T14:25:23.501249Z",
            "url": "https://files.pythonhosted.org/packages/54/b4/2b4e742c4409191c155d81ec6efc8fc828f9629e56e0ac350eb467534207/fast_json_repair-0.1.3-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b4438a3e870bbfc33662f1903625c8ad7d7a478e8ac55ab33f7b91ecbde2587d",
                "md5": "b4c12b9d81b6eb45938ebd87a00a87e9",
                "sha256": "f196945a43d41cef010a376ea2e58439b00e421c184f9d52d191a66e70ce5b92"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b4c12b9d81b6eb45938ebd87a00a87e9",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.11",
            "size": 245847,
            "upload_time": "2025-08-27T14:25:24",
            "upload_time_iso_8601": "2025-08-27T14:25:24.894086Z",
            "url": "https://files.pythonhosted.org/packages/b4/43/8a3e870bbfc33662f1903625c8ad7d7a478e8ac55ab33f7b91ecbde2587d/fast_json_repair-0.1.3-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1d1a6586adac9fda8648f217ec0aa4f3f62ec6f516d3f10a918f9369d8c65f46",
                "md5": "0f73f39d43110b9c36312b322ad8b042",
                "sha256": "e6c12eaa851acffff544083ded516943a48c407334ca9e33023e8cd039cff94c"
            },
            "downloads": -1,
            "filename": "fast_json_repair-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "0f73f39d43110b9c36312b322ad8b042",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 30194,
            "upload_time": "2025-08-27T14:25:26",
            "upload_time_iso_8601": "2025-08-27T14:25:26.153375Z",
            "url": "https://files.pythonhosted.org/packages/1d/1a/6586adac9fda8648f217ec0aa4f3f62ec6f516d3f10a918f9369d8c65f46/fast_json_repair-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-27 14:25:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dvideby0",
    "github_project": "fast_json_repair#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fast-json-repair"
}
        
Elapsed time: 1.28014s