PHPackages                             mindplay/jsonfreeze - 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. mindplay/jsonfreeze

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

mindplay/jsonfreeze
===================

JSON Serialization library

1.3.1(9y ago)3329.0k↓77.1%7[2 issues](https://github.com/mindplay-dk/jsonfreeze/issues)4LGPL-3.0+PHPPHP &gt;=5.3.0

Since May 2Pushed 9y ago3 watchersCompare

[ Source](https://github.com/mindplay-dk/jsonfreeze)[ Packagist](https://packagist.org/packages/mindplay/jsonfreeze)[ RSS](/packages/mindplay-jsonfreeze/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (1)Versions (10)Used By (4)

mindplay/jsonfreeze
===================

[](#mindplayjsonfreeze)

Serialize and unserialize a PHP object-graph to/from a JSON string-representation.

[![Build Status](https://camo.githubusercontent.com/c887b34e180021297ee89004147e9a8dde47c398acc77de7483567f2db8fd0ef/68747470733a2f2f7472617669732d63692e6f72672f6d696e64706c61792d646b2f6a736f6e667265657a652e737667)](https://travis-ci.org/mindplay-dk/jsonfreeze)

Overview
--------

[](#overview)

This library can serialize and unserialize a complete PHP object-graph to/from a JSON string-representation.

This library differs in a number of ways from e.g. `json_encode()`, `serialize()`, `var_export()` and other existing serialization libraries, in a number of important ways.

[Please see here for detailed technical background information](http://stackoverflow.com/questions/10489876).

The most important thing to understand, is that this library is designed to store self-contained object-graphs - it does not support shared or circular object-references. This is by design, and in-tune with good DDD design practices. An object-graph with shared or circular references cannot be stored directly as JSON, in a predictable format, primarily because the JSON data-format is a tree, not a graph.

Usage
-----

[](#usage)

Nothing to it.

```
use mindplay\jsonfreeze\JsonSerializer;

$serializer = new JsonSerializer();

// serialize to JSON:

$string = $serializer->serialize($my_object);

// rebuild your object from JSON:

$object = $serializer->unserialize($string);
```

### Custom Serialization

[](#custom-serialization)

You can define your own un/serialization functions for a specified class:

```
$serializer = new JsonSerializer();

$serializer->defineSerialization(
    MyType::class,
    function (MyType $object) {
        return ["foo" => $object->foo, "bar" => $object->bar];
    },
    function (array $data) {
        return new MyType($data["foo"], $data["bar"]);
    }
);
```

Note that this works only for concrete classes, and not for abstract classes or interfaces - serialization functions apply to precisely one class, although you can of course register the same functions to multiple classes.

#### Date and Time Serialization

[](#date-and-time-serialization)

The `DateTime` and `DateTimeImmutable` classes have pre-registered un/serialization functions supporting a custom format, in which the date/time is stored in the common ISO-8601 date/time format in the UTC timezone, along with the timezone ID - for example:

```
{
    "#type": "DateTime",
    "datetime": "1975-07-07T00:00:00Z",
    "timezone": "America\/New_York"
}

```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

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

Recently: every ~205 days

Total

9

Last Release

3456d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9445f567f43ee7a963270651e40e533634586f959e4df3d5398d001b1cb49be8?d=identicon)[mindplay.dk](/maintainers/mindplay.dk)

---

Top Contributors

[![mindplay-dk](https://avatars.githubusercontent.com/u/103348?v=4)](https://github.com/mindplay-dk "mindplay-dk (19 commits)")

### Embed Badge

![Health badge](/badges/mindplay-jsonfreeze/health.svg)

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45153.1k6](/packages/jstewmc-rtf)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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