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

0.4.0 2026-02-03 08:56 UTC

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.

Latest Version GitHub Actions Test Workflow Status GitHub License

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.