cortexphp / json-repair
Repair invalid JSON strings by fixing common syntax errors like single quotes, unquoted keys, trailing commas, and missing brackets. Perfect for parsing LLM outputs and malformed API responses.
Installs: 249
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 0
Forks: 0
Open Issues: 1
pkg:composer/cortexphp/json-repair
Requires (Dev)
- colinodell/psr-testlogger: ^1.3
- pestphp/pest: ^4.1.4
- pestphp/pest-plugin-type-coverage: ^4.0.3
- phpbench/phpbench: ^1.4
- phpstan/phpstan: ^2.1.32
- phpstan/phpstan-strict-rules: ^2.0
- rector/rector: ^2.2
- symplify/easy-coding-standard: ^13.0
This package is auto-updated.
Last update: 2026-02-17 02:55:22 UTC
README
Repair invalid JSON strings by automatically fixing common syntax errors like single quotes, unquoted keys, trailing commas, and missing brackets.
Requirements
- PHP 8.3+
- JSON PHP extension
Installation
composer require cortexphp/json-repair
Quick Start
use Cortex\JsonRepair\JsonRepairer; use function Cortex\JsonRepair\json_repair; use function Cortex\JsonRepair\json_repair_decode; // Broken JSON (single quotes, unquoted keys, trailing comma) $broken = "{'name': 'John', age: 30, active: true,}"; $repaired = (new JsonRepairer($broken))->repair(); // {"name": "John", "age": 30, "active": true} // Or use the helper function $repaired = json_repair($broken); // Repair and decode in one step $data = (new JsonRepairer($broken))->decode(); // ['name' => 'John', 'age' => 30, 'active' => true] // Or use the helper function $data = json_repair_decode($broken);
Documentation
📚 View Full Documentation →
Credits
License
The MIT License (MIT). Please see License File for more information.