PHPackages                             bernardosecades/php-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. bernardosecades/php-json

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

bernardosecades/php-json
========================

Encode, decode, handle errors and valid json with php

v1.0.0(9y ago)09.8kMITPHPPHP &gt;=5.5

Since Aug 23Pushed 9y ago2 watchersCompare

[ Source](https://github.com/bernardosecades/php-json)[ Packagist](https://packagist.org/packages/bernardosecades/php-json)[ RSS](/packages/bernardosecades-php-json/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

PHP JSON
========

[](#php-json)

[![Build Status](https://camo.githubusercontent.com/9a2069be6d78d2a51ca0655b34d6a17c4538dcedb1722e538f745ef31dfa934a/68747470733a2f2f7472617669732d63692e6f72672f6265726e6172646f736563616465732f7068702d6a736f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bernardosecades/php-json)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/97c83036910c29e4b7bd15002bd2e601823b7354c607b9afa34ac7ab458ebae3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6265726e6172646f736563616465732f7068702d6a736f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bernardosecades/php-json/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/3393c3bc4309e77105e8c9c9808186e3cd805f7148dd1dd7eb0b3626907f9772/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6265726e6172646f736563616465732f7068702d6a736f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bernardosecades/php-json/code-structure/master)[![License](https://camo.githubusercontent.com/7c412cb8bc83dc4085b435beb0b988ccd6cc7b95f6bc47823320cda318274b70/68747470733a2f2f706f7365722e707567782e6f72672f6265726e6172646f736563616465732f7068702d6a736f6e2f6c6963656e7365)](https://packagist.org/packages/bernardosecades/php-json)[![SensioLabsInsight](https://camo.githubusercontent.com/1fc01eb72705ac586e67405805e67d954ebad4f22f0f8cd701a2a81cd874b169/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38653730613131622d376530642d343638332d386661622d3638616631323035623261362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/8e70a11b-7e0d-4683-8fab-68af1205b2a6)

Why?
----

[](#why)

Mainly to handle errors json encode/decode and encapsulate options to encode easily.

Usage
-----

[](#usage)

```
use BernardoSecades\Json\Json;

...

Json::decode($value);
Json::encode($value);
```

Options in json encode:

```
use BernardoSecades\Json\Json;
use BernardoSecades\Json\Option;
use BernardoSecades\Json\ArrayOption;

...

$options = new ArrayOption();
$options[] = Option::JSON_UNESCAPED_UNICODE(); // Use enum object
$options[] = Option::JSON_UNESCAPED_SLASHES();
$options[] = Option::JSON_NUMERIC_CHECK();

Json::encode($value, $options);
```

### Handle errors

[](#handle-errors)

```
use BernardoSecades\Json\Json;
use BernardoSecades\Json\DecodeException;
use BernardoSecades\Json\EncodeException;

...

try {
    Json::decode($value);
} catch (DecodeException $exception) {
    // do something
}

// or

if (!Json::isValid($value)) {
   // do something
}

try {
    Json::encode($value);
} catch (EncodeException $exception) {
 // do something
}
```

Get info from Encode/Decode exception

```
use BernardoSecades\Json\Json;
use BernardoSecades\Json\DecodeException;

...

try {
    Json::decode($value);
} catch (DecodeException $exception) {

    $errorMessage = sprintf('%s , json error code %d',
        $exception->getMessage(), // see http://php.net/manual/en/function.json-last-error-msg.php
        $exception->getCode(),    // see http://php.net/manual/en/json.constants.php
    );

    $this->logger->error($errorMessage);
    // do something more
}
```

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

[](#installation)

```
composer require bernardosecades/php-json

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

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

3597d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1932461?v=4)[Bernardo Secades](/maintainers/bernardosecades)[@bernardosecades](https://github.com/bernardosecades)

---

Top Contributors

[![bernardosecades](https://avatars.githubusercontent.com/u/1932461?v=4)](https://github.com/bernardosecades "bernardosecades (6 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

phpjsonencodedecode

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kherge/json

Encodes, decodes, and validates JSON data.

60234.2k6](/packages/kherge-json)[serafim/json5

JSON5 parser

231.0k](/packages/serafim-json5)

PHPackages © 2026

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