PHPackages                             adhocore/json-fixer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. adhocore/json-fixer

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

adhocore/json-fixer
===================

Fix/repair truncated JSON data

v1.0.1(2y ago)51543.2k↓20.3%7[1 issues](https://github.com/adhocore/php-json-fixer/issues)2MITPHPPHP &gt;=5.4.0CI failing

Since Jul 21Pushed 2y ago4 watchersCompare

[ Source](https://github.com/adhocore/php-json-fixer)[ Packagist](https://packagist.org/packages/adhocore/json-fixer)[ Fund](https://paypal.me/ji10)[ GitHub Sponsors](https://github.com/adhocore)[ RSS](/packages/adhocore-json-fixer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (2)

adhocore/json-fixer
-------------------

[](#adhocorejson-fixer)

PHP library to fix Truncated JSON data by padding contextual counterpart to the end. Works with PHP5.4 or above.

[![Latest Version](https://camo.githubusercontent.com/d261e257086bfc768f20ad1fa9c143053ca58d3d07450c1589532b9f51283d1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6164686f636f72652f7068702d6a736f6e2d66697865722e7376673f7374796c653d666c61742d737175617265)](https://github.com/adhocore/php-json-fixer/releases)[![Travis Build](https://camo.githubusercontent.com/199628df5eb3e3ce1a230ad9b070b67e452415111b22cefd8d135fc455e0ab3d/68747470733a2f2f7472617669732d63692e636f6d2f6164686f636f72652f7068702d6a736f6e2d66697865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/adhocore/php-json-fixer?branch=master)[![Scrutinizer CI](https://camo.githubusercontent.com/5ed1808b0cbd9705bd76cf4d8a5e7592249560773bdb9feb22be7b305a758187/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6164686f636f72652f7068702d6a736f6e2d66697865722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/adhocore/php-json-fixer/?branch=master)[![Codecov branch](https://camo.githubusercontent.com/e468de9e627959468d876c52cf3c08f0d58241ffddcfc921f665cc6139f30945/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6164686f636f72652f7068702d6a736f6e2d66697865722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/adhocore/php-json-fixer)[![StyleCI](https://camo.githubusercontent.com/b64550ee657da047e1c9f09a84390a848c5a25f39ac9aefa28b2e987b2069d1d/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134313538393037342f736869656c64)](https://styleci.io/repos/141589074)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Tweet](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Rescue+and+fix+truncated+JSON+data+in+PHP&url=https://github.com/adhocore/php-json-fixer&hashtags=php,json,jsonfixer,fixjson)[![Support](https://camo.githubusercontent.com/6687993dc9b60228356720a501b7c197c8c9a82194cac1b1c72d0dea95e6ad32/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d537570706f7274266d6573736167653d254532253944254134266c6f676f3d476974487562)](https://github.com/sponsors/adhocore)

- Zero dependency (no vendor bloat).

**It is a work in progress and might not cover all edge cases.** It would be great if you try it out, open some issues or contribute.

Installation
------------

[](#installation)

```
composer require adhocore/json-fixer
```

Usage
-----

[](#usage)

```
use Ahc\Json\Fixer;

$json = (new Fixer)->fix('{"a":1,"b":2');
// {"a":1,"b":2}

$json = (new Fixer)->fix('{"a":1,"b":true,');
// {"a":1,"b":true}

$json = (new Fixer)->fix('{"b":[1,[{"b":1,"c"');
// {"b":[1,[{"b":1,"c":null}]]}

// For batch fixing, you can just reuse same fixer instance:
$fixer = new Fixer;

$fixer->fix('...');
$fixer->fix('...');
// ...
```

Error
-----

[](#error)

If there's error and fixer cant fix the JSON for some reason, it will throw a `RuntimeException`. You can disable this behavior by passing silent flag (2nd param) to `fix()` in which case original input is returned:

```
(new Fixer)->silent()->fix('invalid');
// 'invalid'

(new Fixer)->silent(true)->fix('invalid');
// 'invalid'

(new Fixer)->silent(false)->fix('invalid');
// RuntimeException
```

Missing Value
-------------

[](#missing-value)

By default missing values are padded with `null`. You can change it passing desired value to `missingValue()`:

```
// key b is missing value and is padded with `null`
$json = (new Fixer)->fix('{"a":1,"b":');
// {"a":1,"b":null}

// key b is missing value and is padded with `true`
$json = (new Fixer)->missingValue(true)->fix('{"a":1,"b":');
// {"a":1,"b":true}

// key b is missing value and is padded with `"truncated"`
// Note that you can actually inject a whole new JSON subset as 3rd param
// but that should be a valid JSON segment and is not checked by fixer.
$json = (new Fixer)->missingValue('"truncated"')->fix('{"a":1,"b":');
// {"a":1,"b":"truncated"}
```

Todo
----

[](#todo)

- Configurable missing value as per context (options)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 84.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~379 days

Recently: every ~473 days

Total

6

Last Release

963d ago

Major Versions

v0.0.4 → v1.0.02022-10-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2908547?v=4)[Jitendra Adhikari](/maintainers/adhocore)[@adhocore](https://github.com/adhocore)

---

Top Contributors

[![adhocore](https://avatars.githubusercontent.com/u/2908547?v=4)](https://github.com/adhocore "adhocore (55 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (4 commits)")[![snapshotpl](https://avatars.githubusercontent.com/u/312655?v=4)](https://github.com/snapshotpl "snapshotpl (2 commits)")[![Rezonanzo](https://avatars.githubusercontent.com/u/4403488?v=4)](https://github.com/Rezonanzo "Rezonanzo (1 commits)")[![ockstadt](https://avatars.githubusercontent.com/u/36147797?v=4)](https://github.com/ockstadt "ockstadt (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

adhocorefix-jsonfix-truncated-jsonhacktoberfestjsonpad-jsonphprecover-jsonrectify-jsonphpjsonphp-json-fixertruncated-jsonjson-fixertruncation-fixerrectify-jsonfix-json

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adhocore-json-fixer/health.svg)

```
[![Health](https://phpackages.com/badges/adhocore-json-fixer/health.svg)](https://phpackages.com/packages/adhocore-json-fixer)
```

###  Alternatives

[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
