PHPackages                             mszewcz/php-json-utils - 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. mszewcz/php-json-utils

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

mszewcz/php-json-utils
======================

JSON utility class

1.0.0(8y ago)02302MITPHPPHP &gt;=7.1.0

Since Nov 1Pushed 8y agoCompare

[ Source](https://github.com/mszewcz/php-json-utils)[ Packagist](https://packagist.org/packages/mszewcz/php-json-utils)[ RSS](/packages/mszewcz-php-json-utils/feed)WikiDiscussions develop Synced 4d ago

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

php-json-utils
==============

[](#php-json-utils)

JSON utility class, which provides encoding, decoding, base64url encoding and base64url decoding methods.

[![Build Status](https://camo.githubusercontent.com/7a7988320692fbcb2fceb31de450b5236120087c05f904c3e520686e918fab3f/68747470733a2f2f7472617669732d63692e636f6d2f6d737a6577637a2f7068702d6a736f6e2d7574696c732e7376673f746f6b656e3d534b487955753744396b326778667935614b7058266272616e63683d646576656c6f70)](https://travis-ci.com/mszewcz/php-json-utils)[![Codacy Badge](https://camo.githubusercontent.com/02a54b2d9f128f2f66f8413115689c18e1414b58ce03cfcd9e4a66d84b38d8e9/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3930636538363039323335663465663238393861613362323361363535613865)](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=mszewcz/php-json-utils&utm_campaign=Badge_Grade)[![Codacy Badge](https://camo.githubusercontent.com/75e7093781e5a4713b03aff23b24da6cf5fe9bb72110aa902761fa9a85193071/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f3930636538363039323335663465663238393861613362323361363535613865)](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=mszewcz/php-json-utils&utm_campaign=Badge_Coverage)

Contents
--------

[](#contents)

- [Installation](#Installation)
- [Usage](#Usage)
- [Contributing](#Contributing)
- [License](#License)

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

[](#installation)

If you use [Composer](http://getcomposer.org/) to manage the dependencies simply add a dependency on `mszewcz/php-json-utils` to your project's composer.json file. Here is a minimal example of a composer.json:

```
{
    "require": {
        "mszewcz/php-json-utils": ">=1.0"
    }
}

```

You can also clone or download this respository.

**php-json-utils** meets [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloading standards. If using the Composer please include its autoloader file:

```
require_once 'vendor/autoload.php';
```

If you cloned or downloaded this repository, you will have to code your own PSR-4 style autoloader implementation.

Usage
-----

[](#usage)

To encode data into JSON string:

```
use MS\Json\Utils\Utils;

$obj = new \stdClass();
$obj->flt = 5.5;
$obj->bool = true;

$data = ['int' => 8, 'str' => 'test/Ʃ', 'arr' => [$obj]];

$utils = new Utils();
try {
    $encoded = $utils->encode($data);
} catch (\Exception $e) {
    echo $e->getMessage();
}
```

To decode JSON string:

```
use MS\Json\Utils\Utils;

$json = '{"int":8,"str":"test/Ʃ","arr":[{"flt":5.5,"bool":true}]}';

$utils = new Utils();
try {
    $decoded = $utils->decode($json);
} catch (\Exception $e) {
    echo $e->getMessage();
}
*/
```

To base64url encode string:

```
use MS\Json\Utils\Utils;

$data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eget purus ';
$data.= 'consectetur eros pellentesque ullamcorper. Sed justo tellus, porttitor non ';
$data.= 'porta ac, euismod eu mauris. Nam maximus pretium dapibus. Pellentesque in elit ';
$data.= 'placerat, sagittis justo id, elementum elit. Maecenas dignissim dui ac lectus ';
$data.= 'pretium condimentum. Morbi id ipsum in urna egestas varius in vitae quam. ';
$data.= 'Phasellus efficitur elementum sapien id dictum.';

$utils = new Utils();
$encoded = $utils->base64UrlEncode($data);
```

To base64url decode string:

```
use MS\Json\Utils\Utils;

$data = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4';
$data.= 'gTnVuYyBlZ2V0IHB1cnVzIGNvbnNlY3RldHVyIGVyb3MgcGVsbGVudGVzcXVlIHVsbGFtY29ycG';
$data.= 'VyLiBTZWQganVzdG8gdGVsbHVzLCBwb3J0dGl0b3Igbm9uIHBvcnRhIGFjLCBldWlzbW9kIGV1I';
$data.= 'G1hdXJpcy4gTmFtIG1heGltdXMgcHJldGl1bSBkYXBpYnVzLiBQZWxsZW50ZXNxdWUgaW4gZWxp';
$data.= 'dCBwbGFjZXJhdCwgc2FnaXR0aXMganVzdG8gaWQsIGVsZW1lbnR1bSBlbGl0LiBNYWVjZW5hcyB';
$data.= 'kaWduaXNzaW0gZHVpIGFjIGxlY3R1cyBwcmV0aXVtIGNvbmRpbWVudHVtLiBNb3JiaSBpZCBpcH';
$data.= 'N1bSBpbiB1cm5hIGVnZXN0YXMgdmFyaXVzIGluIHZpdGFlIHF1YW0uIFBoYXNlbGx1cyBlZmZpY';
$data.= '2l0dXIgZWxlbWVudHVtIHNhcGllbiBpZCBkaWN0dW0u';

$utils = new Utils();
$decoded = $utils->base64UrlDecode($data);
```

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

[](#contributing)

Contributions are welcome. Please send your contributions through GitHub pull requests

Pull requests for bug fixes must be based on latest stable release from the `master` branch whereas pull requests for new features must be based on the `developer` branch.

Due to time constraints, I'm not always able to respond as quickly as I would like. If you feel you're waiting too long for merging your pull request please remind me here.

#### Coding standards

[](#coding-standards)

We follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style and [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloading standards. Be sure you're also following them before sending your pull request.

License
-------

[](#license)

**php-json-utils** is licensed under the MIT License - see the `LICENSE` file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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

3117d ago

### Community

Maintainers

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

---

Top Contributors

[![mszewcz](https://avatars.githubusercontent.com/u/31341235?v=4)](https://github.com/mszewcz "mszewcz (8 commits)")

---

Tags

phpjsonutilsutilitiesphp-json-utils

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mszewcz-php-json-utils/health.svg)

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

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[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)
