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

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

codekandis/json-codec
=====================

With the JSON codec you will be able to encode into and decode from JSON data in an object oriented way. It wraps PHP's functions `json\_encode()` and `json\_decode()`.

2.0.0(5y ago)06752MITPHPPHP ^7.4

Since Dec 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/codekandis/json-codec)[ Packagist](https://packagist.org/packages/codekandis/json-codec)[ RSS](/packages/codekandis-json-codec/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (4)Versions (4)Used By (2)

codekandis/json-codec
=====================

[](#codekandisjson-codec)

[![Version](https://camo.githubusercontent.com/55f30def4a68344c0de905e67851fe21552f126e98f7c99bbe794e47be861c23/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d332e302e302d626c75652e737667)](./CHANGELOG.md)[![License](https://camo.githubusercontent.com/07a7d0169027aac6d7a0bfa8964dfef5fbc40d5a2075cabb3d8bc67e17be3451/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d79656c6c6f772e737667)](./LICENSE)[![Minimum PHP Version](https://camo.githubusercontent.com/9c50dc780fa576f5c39b4feff00c05345c1471be0808881a09e750b91220dc54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e332d3838393242462e737667)](https://php.net)[![Code Coverage](https://camo.githubusercontent.com/af813ae002de8e31bfd234a3d5eab4fe1963ed998df54d1f3c5e3e1fe334f7d6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e2e737667)](https://camo.githubusercontent.com/af813ae002de8e31bfd234a3d5eab4fe1963ed998df54d1f3c5e3e1fe334f7d6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e2e737667)

With the JSON codec you will be able to encode into and decode from JSON data in an object oriented way. It wraps PHP's functions [`json_encode()`](https://www.php.net/manual/en/function.json-encode.php) and [`json_decode()`](https://www.php.net/manual/en/function.json-decode.php).

Index
-----

[](#index)

- [Installation](#installation)
- [How to use](#how-to-use)
    - [Encoding values](#encoding-values)
    - [Decoding values](#decoding-values)
- [Differences to PHP's JSON functions](#differences-to-phps-json-functions)

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

[](#installation)

Install the latest version with

```
$ composer require codekandis/json-codec
```

How to use
----------

[](#how-to-use)

### Encoding values

[](#encoding-values)

The following example shows how to encode a value.

```
$value = [
  'foo',
  'bar'
];

( new JsonEncoder() )
  ->encode( $value );

$options = new JsonEncoderOptions( JsonEncoderOptions::FORCE_OBJECT | JsonEncoderOptions::PRETTY_PRINT );
( new JsonEncoder() )
  ->encode( $value, $options );
```

### Decoding values

[](#decoding-values)

The following examples show how to decode a value.

```
$value = '{"0":"foo","1":"bar"}';

( new JsonDecoder() )
  ->decode( $value );

$options = new JsonDecoderOptions( JsonDecoderOptions::OBJECT_AS_ARRAY );
( new JsonDecoder() )
  ->decode( $value, $options );

$options        = new JsonDecoderOptions( JsonDecoderOptions::OBJECT_AS_ARRAY );
$recursionDepth = 2;
( new JsonDecoder() )
  ->decode( $value, $options, $recursionDepth );
```

Differences to PHP's JSON functions
-----------------------------------

[](#differences-to-phps-json-functions)

[`json_decode()`](https://www.php.net/manual/en/function.json-encode.php) accepts an additional argument [`$assoc`](https://www.php.net/manual/en/function.json-decode.php#refsect1-function.json-decode-parameters) to specify if the value forced to be decoded into an associative array. This argument is omitted in the [`JsonDecoder`](./src/JsonDecoder.php) while this behaviour can be set explicitly with the [`JsonDecoderOptions::OBJECT_TO_ARRAY`](./src/JsonDecoderOptions.php).

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

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

Every ~386 days

Total

2

Last Release

1984d ago

Major Versions

1.0.0 → 2.0.02021-01-17

PHP version history (2 changes)1.0.0PHP ^7.3

2.0.0PHP ^7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31327217?v=4)[Christian Ramelow](/maintainers/codekandis)[@codekandis](https://github.com/codekandis)

---

Top Contributors

[![codekandis](https://avatars.githubusercontent.com/u/31327217?v=4)](https://github.com/codekandis "codekandis (44 commits)")

---

Tags

codecdecoderencoderjsonphpphpjsonencodedecodecodecjson codec

### Embed Badge

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

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

###  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)
