PHPackages                             dnonov/json-parser - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dnonov/json-parser

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dnonov/json-parser
==================

Thin wrapper around `json\_decode` and `json\_encode` with exceptions and some handy methods.

v1.0.2(1y ago)014MITPHP

Since Sep 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DNonov/JSONParser)[ Packagist](https://packagist.org/packages/dnonov/json-parser)[ RSS](/packages/dnonov-json-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

JSONParser
==========

[](#jsonparser)

[![Latest Version on Packagist](https://camo.githubusercontent.com/35507bda055beadfcf47da6c510d989383616b8010686b95286923f99c5a8d44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646e6f6e6f762f6a736f6e2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dnonov/json-parser)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dee93a51cff867a5d4c02f98f2646cb885bd6ec6d50f671e71c422ada0fbdb16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f444e6f6e6f762f4a534f4e5061727365722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/DNonov/JSONParser/actions?query=workflow%3Arun-tests+branch%3Amain)

About
-----

[](#about)

Thin wrapper around `json_decode` and `json_encode` with exceptions and some handy methods.

Requirements
------------

[](#requirements)

PHP 7.4^

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

[](#installation)

You can install the package via composer:

```
composer require dnonov/json-parser
```

Description
-----------

[](#description)

This mainly exists because of the silent `json_decode`; if something's wrong it will return `null`. I prefer exceptions and nicer method names. It is very thin wrapper around three functions in PHP standard library, but I'm tired of re-writing it every time.

### Here's how to use it

[](#heres-how-to-use-it)

```
use Dnonov\JsonParser\Facades\JSONParser;

$arrayData = JSONParser::decodeToArray("[{"one": 1, "two": 2}]");
$objectData = JSONParser::decodeToObject("[{"one": 1, "two": 2}]");

$array = ["one" => 1, "two" => 2];
$encodedArrayData = JSONParser::encode($array);

// Make sure file path is relative to `base_path()`.
$arrayFileData = JSONParser::decodeFromFileToArray("./data.json");
$objectFileData = JSONParser::decodeFromFileToObject("./data.json");

// There are some handy methods.
$object = JSONParser::arrayToObject(["one" => 1, "two" => 2]);
$array = JSONParser::objectToArray($object);
```

### Various exceptions might be thrown during decoding and encoding.

[](#various-exceptions-might-be-thrown-during-decoding-and-encoding)

- JsonMaxDepthException
- JsonInvalidOrMalformedException
- JsonControlCharacterException
- JsonSyntaxErrorException
- JsonMalformedUTF8Exception
- JsonRecursiveReferenceException
- JsonInfinityOrNanDetectedException
- JsonUnsupportedTypeException
- JsonException
- InvalidArgumentExceptions

Here's documentation on the equivalent errors in [PHP Doc](https://www.php.net/manual/en/json.constants.php#constant.json-throw-on-error)

Contributing
------------

[](#contributing)

Bug reports and pull requests are always welcome.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

623d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c9b9c74bac0b4e545ec3b9ea54984f1b0e1e4e73fdc229072f6f31ccaaf3710?d=identicon)[dnonov](/maintainers/dnonov)

---

Top Contributors

[![DNonov](https://avatars.githubusercontent.com/u/30554034?v=4)](https://github.com/DNonov "DNonov (23 commits)")

### Embed Badge

![Health badge](/badges/dnonov-json-parser/health.svg)

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

###  Alternatives

[mention/fast-doctrine-paginator

Fast Doctrine paginator for batching, infinite scrolling, Relay

18117.9k](/packages/mention-fast-doctrine-paginator)

PHPackages © 2026

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