PHPackages                             devlop/json - 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. devlop/json

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

devlop/json
===========

Simple JSON wrapper for better experience working with json data

1.3.2(4y ago)086MITPHPPHP ^7.4|^8.0

Since Dec 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/devlop/json)[ Packagist](https://packagist.org/packages/devlop/json)[ RSS](/packages/devlop-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (10)Used By (0)

 [![Latest Stable Version](https://camo.githubusercontent.com/84ddeb09b7a19e409054ea23e8bce925af92663bd70143a7048a32cafc2c79c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465766c6f702f6a736f6e)](https://packagist.org/packages/devlop/json) [![License](https://camo.githubusercontent.com/6c1d2a52609efcadb1d46a37d5b33d14d9dc4ed8cde19f15e39900c95dc4c467/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465766c6f702f6a736f6e)](https://github.com/devlop/json/blob/master/LICENSE.md)

Json
====

[](#json)

JSON wrapper that provide better developer experience than the native `json_encode` and `json_decode`.

Installation
============

[](#installation)

```
composer require devlop/json
```

Differences to json\_encode / json\_decode
==========================================

[](#differences-to-json_encode--json_decode)

- Always throws `\JsonException` on errors
- Consistent order of arguments (`$value`/`$json`, `$flags`, `$depth`)
- Stricter when encoding and decoding, only supports arrays and objects, does not support scalar values

Usage
=====

[](#usage)

Both encode and decode are static methods and have the same order of arguments: `first the input`, followed by `int $flags` and lastly `int $depth`.

Encoding
--------

[](#encoding)

The `encode` method is a wrapper for the native [json\_encode](https://www.php.net/manual/en/function.json-encode.php) method.

Signature: `public static function encode(array|object $value, int $flags = 0, int $depth = 512) : string`

```
use Devlop\Json\Json;

$output = Json::encode($input);

// or with flags
$output = Json::encode($input, \JSON_HEX_TAG | \JSON_NUMERIC_CHECK);
```

Encoding (Pretty Print)
-----------------------

[](#encoding-pretty-print)

The `pretty` method is a convenience method to get pretty formatted output without having to manually specify the [`JSON_PRETTY_PRINT`](https://www.php.net/manual/en/json.constants.php#constant.json-pretty-print) flag.

It has the same signature as `encode()`.

```
use Devlop\Json\Json;

$output = Json::pretty($input);

// or with flags
$output = Json::encode($input, \JSON_HEX_TAG | \JSON_NUMERIC_CHECK);
```

Decoding
--------

[](#decoding)

The `decode` method is a wrapper for the native [json\_decode](https://www.php.net/manual/en/function.json-decode.php) method.

Signature: `public static function decode(string $json, int $flags = 0, int $depth = 512) : array|object`

```
use Devlop\Json\Json;

$output = Json::decode($input);

// or with flags
$output = Json::decode($input, \JSON_INVALID_UTF8_IGNORE);
```

Decoding (Associative)
----------------------

[](#decoding-associative)

The `decodeAssoc` method is a convenience method to decode but force all objects to associative arrays without having to manually specify the [`JSON_OBJECT_AS_ARRAY`](https://www.php.net/manual/en/json.constants.php#constant.json-object-as-array) flag.

It has the same signature as `decode()`.

```
use Devlop\Json\Json;

$output = Json::decodeAssoc($input);

// or with flags
$output = Json::decodeAssoc($input, \JSON_INVALID_UTF8_IGNORE);
```

Error handling
==============

[](#error-handling)

Any time an error occurs the native `JsonException` will be thrown.

Supported types
===============

[](#supported-types)

My belief is that the most common usage of JSON in PHP is to store a JSON representation of arrays or objects. It is true that a single string, integer, boolean or even a single null value is a valid JSON document, but if you are as me and only using JSON for arrays or objects then it's just easier to treat anything else as invalid data and throw an exception, this removes some of the need to check the type after decoding.

depth argument and NO\_FLAGS
============================

[](#depth-argument-and-no_flags)

If you want to access the $depth argument without adding any additional flags, you must supply the default value `0` for the `$flags` argument, but to make the experiance more clearer you can use the constant `Json::NO_FLAGS` instead.

```
$output = Json::encode($input, Json::NO_FLAGS, 3);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~38 days

Recently: every ~58 days

Total

9

Last Release

1669d ago

Major Versions

0.1.0 → 1.0.02021-02-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/caa865d4467587eecd242fadf805f15ce436c9d7efa7786b49b69a193c158aaf?d=identicon)[johanrosenson](/maintainers/johanrosenson)

---

Top Contributors

[![johanrosenson](https://avatars.githubusercontent.com/u/10432296?v=4)](https://github.com/johanrosenson "johanrosenson (26 commits)")

---

Tags

jsonphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[danielgsims/php-collections

Collection classes for PHP

141409.1k8](/packages/danielgsims-php-collections)[roolith/event

PHP event listener

1551.6k1](/packages/roolith-event)

PHPackages © 2026

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