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

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

rahulmac/json
=============

json is a fluent, object-oriented wrapper around PHP’s native JSON functions.

v1.0.0(3mo ago)3202↓50%MITPHPCI passing

Since Feb 8Pushed 3mo agoCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

 [![Packagist Version](https://camo.githubusercontent.com/fde6cf949c097f2ef7d3f79ccfbe83a1469c2ebbfcf33b61d105cac693f004af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726168756c6d61632f6a736f6e)](https://packagist.org/packages/rahulmac/json) [![GitHub License](https://camo.githubusercontent.com/3fe5f961bd54170d11908fefd62fdaf182e99540c5bef762d189af5635d579db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f526168756c2d4d61632f6a736f6e)](https://github.com/Rahul-Mac/json/blob/main/LICENSE) [![Tests](https://github.com/Rahul-Mac/json/actions/workflows/test.yml/badge.svg)](https://github.com/Rahul-Mac/json/actions/workflows/test.yml)

json
====

[](#json)

`json` is a fluent, object-oriented wrapper around PHP’s native JSON functions.

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

[](#installation)

```
composer require rahulmac/json
```

Prerequisites
=============

[](#prerequisites)

- PHP v8.0+

Usage
=====

[](#usage)

Encoding JSON
-------------

[](#encoding-json)

Use `Json::from()` to encode PHP values into JSON.

```
use Rahulmac\Json\Json;

$json = Json::from(['foo' => 'bar'])->stringify();
```

To pretty-print:

```
$json = Json::from(['foo' => 'bar'])->prettify();
```

Using custom flags and depth:

```
$json = Json::from($data)
    ->withFlags(JSON_UNESCAPED_SLASHES)
    ->withDepth(256)
    ->stringify();
```

Decoding JSON
-------------

[](#decoding-json)

Use `Json::of()` to decode a JSON string.

```
use Rahulmac\Json\Json;

$value = Json::of('{"foo":"bar"}')->parse();
```

To decode as an array:

```
$array = Json::of('{"foo":"bar"}')->toArray();
```

To validate:

```
$isValid = Json::of('{"foo":"bar"}')->isValid(); // true
$isValid = Json::of('{invalid json}')->isValid(); // false
```

### Accessors &amp; Key-Existence

[](#accessors--key-existence)

Use `get()` with dot notation to access nested values:

```
use Rahulmac\Json\Json;

$decoder = Json::of('{"user":{"id":123,"name":"Alice","active":true,"balance":99.5}}');

$id      = $decoder->get('user.id');          // 123
$name    = $decoder->get('user.name');      // "Alice"
$status  = $decoder->get('user.active');  // true
$unknown = $decoder->get('user.unknown', 'default'); // "default"
```

For type-safety, use can use type-safe helpers that fetch a value and cast it to the requested type:

```
$age     = $decoder->asInt('user.id');           // 123
$balance = $decoder->asFloat('user.balance');   // 99.5
$name    = $decoder->asString('user.name');     // "Alice"
$active  = $decoder->asBool('user.active');     // true

$roles   = $decoder->asArray('user.roles', []); // [] if missing
```

To determine if a key exists:

```
Json::of('{"foo":"bar"}')->has('foo'); // true
Json::of('{"foo":"bar"}')->has('baz'); // false
Json::of('{"foo":{"bar":"baz"}')->has('foo.bar'); // true
Json::of('{"foo":{"bar":"baz"}')->has('foo.baz'); // false
```

Note

While encoding/decoding use `addFlags()` to append flags and `withFlags()` to override them.

Warning

All encoding/decoding/accessor/key-existence methods throw `\JsonException` if an invalid JSON is received.

License
=======

[](#license)

`json` is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance81

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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

Every ~0 days

Total

3

Last Release

99d ago

Major Versions

v0.2.0 → v1.0.02026-02-08

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22441472?v=4)[Rahul Makwana](/maintainers/rahulmac)[@rahulmac](https://github.com/rahulmac)

---

Top Contributors

[![Rahul-Mac](https://avatars.githubusercontent.com/u/61614844?v=4)](https://github.com/Rahul-Mac "Rahul-Mac (14 commits)")

---

Tags

jsonphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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