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

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

vishalshakya/json-handler
=========================

A package for simplified JSON handling in PHP

v1.0.0(2y ago)04MITPHP

Since Jun 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/shakya-vishal/Json-Handler)[ Packagist](https://packagist.org/packages/vishalshakya/json-handler)[ RSS](/packages/vishalshakya-json-handler/feed)WikiDiscussions master Synced 1mo ago

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

JSON Handler
============

[](#json-handler)

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

[](#installation)

Install the package using [Composer](https://getcomposer.org/):

```
composer require vishalshakya/json-handler
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- PHPUnit (for running tests, required only for development)

Usage
-----

[](#usage)

To use the `JsonHandler` class, make sure to import it into your PHP file:

```
use Vishalshakya\JsonHandler;
```

### Encoding Data

[](#encoding-data)

The `encode` method allows you to convert an array or object into a JSON string:

```
$data = ['name' => 'John Doe', 'age' => 25];

$jsonString = JsonHandler::encode($data);

echo $jsonString;
```

Output:

```
{"name":"John Doe","age":25}

```

### Decoding JSON Strings

[](#decoding-json-strings)

The `decode` method converts a JSON string into a PHP data structure. By default, it returns an object:

```
$jsonString = '{"name":"John Doe","age":25}';

$object = JsonHandler::decode($jsonString);

echo $object->name; // John Doe
echo $object->age;  // 25
```

If you want to decode the JSON string into an associative array, pass `true` as the second argument:

```
$jsonString = '{"name":"John Doe","age":25}';

$array = JsonHandler::decode($jsonString, true);

echo $array['name']; // John Doe
echo $array['age'];  // 25
```

Exception Handling
------------------

[](#exception-handling)

The `JsonHandler` class throws exceptions to indicate errors in encoding or decoding JSON data. Here are the possible exceptions:

- `InvalidArgumentException` is thrown when the input data type is invalid or the JSON string is not valid.
- `JsonException` is thrown when there is an error in the JSON encoding or decoding process.

Make sure to handle these exceptions appropriately in your code.

Development
-----------

[](#development)

If you want to run the tests for this package, make sure you have PHPUnit installed. You can install it using Composer:

```
composer require --dev phpunit/phpunit
```

Then, run the tests with the following command:

```
vendor/bin/phpunit
```

License
-------

[](#license)

This package is open source and released under the [MIT License](https://github.com/your-username/your-package/blob/main/LICENSE). Feel free to modify and distribute it as needed.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

1058d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23446f29cf21ccd2403b631f3f2b0b82d024359e206adcd589f57b0e919275b1?d=identicon)[vishalshakya](/maintainers/vishalshakya)

---

Top Contributors

[![vishalshakya-dev](https://avatars.githubusercontent.com/u/100135136?v=4)](https://github.com/vishalshakya-dev "vishalshakya-dev (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[breadlesscode/neos-nodetypes-folder

Folder nodetype for Neos CMS

1088.5k1](/packages/breadlesscode-neos-nodetypes-folder)

PHPackages © 2026

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