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

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

sgmendez/json
=============

A PHP library for manipulate JSON data

v1.0.5(10y ago)1771BSD-2-ClausePHPPHP &gt;=5.3.3

Since Mar 18Pushed 10y ago1 watchersCompare

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

READMEChangelog (7)DependenciesVersions (8)Used By (1)

[![License](https://camo.githubusercontent.com/afcaa8efe33fe73b3e62f68b0cecea0d70116db64552ce6b27e115ee38eced49/68747470733a2f2f706f7365722e707567782e6f72672f73676d656e64657a2f6a736f6e2f6c6963656e73652e737667)](https://packagist.org/packages/sgmendez/json)[![SensioLabsInsight](https://camo.githubusercontent.com/87b00e2a494893b2f6d75a3a0e9f9c3cf51ec746f0f5fd08023001030eb38dfb/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66336534633833392d343965612d343036352d383337302d3065393837353861373036322f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f3e4c839-49ea-4065-8370-0e98758a7062)[![Latest Stable Version](https://camo.githubusercontent.com/d287126c576a3fd621c3ab3b683934d848e52f6544d69abf1ff23e4f144837cb/68747470733a2f2f706f7365722e707567782e6f72672f73676d656e64657a2f6a736f6e2f762f737461626c652e737667)](https://packagist.org/packages/sgmendez/json)[![Total Downloads](https://camo.githubusercontent.com/1bc68ddf8d3d712557a3adc6956accf83abbfd0e91ae21285dd129ee16a2969b/68747470733a2f2f706f7365722e707567782e6f72672f73676d656e64657a2f6a736f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/sgmendez/json)[![Latest Unstable Version](https://camo.githubusercontent.com/2743209e8b2cd3dc2fb65251794e7b3632d305d656fabd052b433634feb9dd25/68747470733a2f2f706f7365722e707567782e6f72672f73676d656e64657a2f6a736f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/sgmendez/json)

Introduction
============

[](#introduction)

---

This PHP library create a wrapper for `json_encode` and `json_decode` PHP functions that normalize use across de PHP versions and throw exceptions when encoding or decoding fail.

Requirements
============

[](#requirements)

---

This library require PHP 5.3.3 or higher

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

[](#installation)

---

You can use [Composer](https://getcomposer.org) to use this library in your application.

If you don't have Composer yet, download it following the instructions on  or just run the following command:

```
curl -s http://getcomposer.org/installer | php

```

And then execute this command to add libary to your project:

```
$ composer require sgmendez/json

```

Or require [`sgmendez/json`](http://sgmendez.github.io/json/)into your `composer.json` file:

```
json
{
    "require": {
        "sgmendez/json": "*"
    }
}

```

Tests
=====

[](#tests)

---

You can run the PHPUnit tests, in directory test execute:

```
$ php phpunit.phar .

```

In this directory there are a copy of phpunit.phar for execution test

Examples
========

[](#examples)

---

Encode JSON data:

```
php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $arrayData = array('foo' => 'Foo', 'bar' => 'Bar');
    $jsonData = $json->encode($arrayData);
}
catch (Exception $ex)
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage().' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}

```

Decode JSON string (by default, return array data):

```
php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $jsonData = '{"foo":"Foo","bar":"Bar"}';
    $dataArray = $json->decode($jsonData);
}
catch (Exception $ex)
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage() .
         ' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}

```

Decode JSON file (by default, return array data):

```
php
use Sgmendez\Json\Json;

$json = new Json();

try
{
    $dataArray = $json->decodeFile('/path/to/file.json');
}
catch (Exception $ex)
{
    echo '[EXCEPTION] MSG: '.$ex->getMessage() .
         ' | FILE: '.$ex->getFile().': '.$ex->getLine()."\n";
}

```

If you need to check if is valid json data, you can to use `checkValidJsonData()` method.

License
=======

[](#license)

---

Licensed under the BSD License:

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

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 ~27 days

Recently: every ~40 days

Total

7

Last Release

3918d ago

### Community

Maintainers

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

---

Top Contributors

[![sgmendez](https://avatars.githubusercontent.com/u/464341?v=4)](https://github.com/sgmendez "sgmendez (13 commits)")

---

Tags

jsonencodedecode

### Embed Badge

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

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

###  Alternatives

[yethee/tiktoken

PHP version of tiktoken

1583.1M15](/packages/yethee-tiktoken)[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)[gioni06/gpt3-tokenizer

PHP package for Byte Pair Encoding (BPE) used by GPT-3.

85537.5k8](/packages/gioni06-gpt3-tokenizer)[devium/toml

A PHP encoder/decoder for TOML compatible with specification 1.0.0

3968.9k13](/packages/devium-toml)[pmjones/throwable-properties

Copies properties of a Throwable to a serializable object.

1554.7k2](/packages/pmjones-throwable-properties)[rickselby/nbt

Parser/Writer for the NBT file format

171.2k1](/packages/rickselby-nbt)

PHPackages © 2026

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