PHPackages                             maciej-sz/pj-freeze - 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. maciej-sz/pj-freeze

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

maciej-sz/pj-freeze
===================

PHP to JSON Serializer/Deserializer

0.2.1(9y ago)01.2kMITPHPPHP &gt;=5.6

Since Aug 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/maciej-sz/pj-freeze)[ Packagist](https://packagist.org/packages/maciej-sz/pj-freeze)[ RSS](/packages/maciej-sz-pj-freeze/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (4)Used By (0)

pj-freeze
=========

[](#pj-freeze)

PHP to JSON Serializer/Deserializer

[![Latest Version on Packagist](https://camo.githubusercontent.com/7bf2bda9b326b59c1cfb70cb490f916043a13be56adff8dd10f0978955d0a1b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616369656a2d737a2f706a2d667265657a652e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/maciej-sz/pj-freeze)[![Build Status](https://camo.githubusercontent.com/29d77be8fcdfe7e320b996b6edd69cc553a82b2bc952479fa9ff91689e3c6de8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d616369656a2d737a2f706a2d667265657a652f6d61737465722e7376673f7374796c653d706c6173746963)](https://travis-ci.org/maciej-sz/pj-freeze)[![No dependencies](https://camo.githubusercontent.com/1ae5ca42e47bf4e50e4a41c131c354a889b3a4a7a02ad7df75ad3395648a2da7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d6e6f6e652d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/maciej-sz/pj-freeze)[![MIT License](https://camo.githubusercontent.com/55d5f880eab481a2416a276bdfb1350ff0ed88b63fb97d54ea9f1282836a89c3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d706c6173746963)](https://github.com/maciej-sz/pj-freeze/blob/master/LICENSE)

Features
--------

[](#features)

- Serialization to JSON
- Unserialization from JSON
- Circular-reference handling
- [Corresponding JavaScript library](https://github.com/maciej-sz/jp-freeze) is available to read serialized data on the browser side

Usage
-----

[](#usage)

This package can be used to serialize and unserialize data objects that contain circular references.

#### Example: basic round-trip

[](#example-basic-round-trip)

```
use MaciejSz\PjFreeze\PjFreeze;

$Freeze = new PjFreeze();

$data = ["foo", "bar", "baz"];

$SerializationResult = $Freeze->serialize($data);
$serializedObj = $SerializationResult->jsonSerialize();

$unserialized = $Freeze->unserialize($serializedObj);
assert($data == $unserialized);
```

#### Example: persisting round-trip

[](#example-persisting-round-trip)

An additional step is required for the serialization result to be persisted: PHP's standard `json_encode()` function has to be called. The `json_encode()` won't produce "*Recursion detected*" error this time.

```
use MaciejSz\PjFreeze\PjFreeze;

$Freeze = new PjFreeze();

$data = ["foo", "bar", "baz"];
$serializedObj = $Freeze->serialize($data)->jsonSerialize();
$serialized_str = json_encode($serializedObj);

file_put_contents("/tmp/data.json", $serialized_str);
// ...
$contents_str = file_get_contents("/tmp/data.json");
$unserialized = $Freeze->unserializeJson($contents_str);
assert($data == $unserialized);
```

#### Example: circular reference

[](#example-circular-reference)

Using only `json_encode()`:

```
// WARNING: this is an example of how NOT to encode circular references
use MaciejSz\PjFreeze\PjFreeze;

$data = new \stdClass();
$data->recursion = $data; // circular reference

$raw_encoded = json_encode($data);
echo json_last_error_msg(); // "Recursion detected"
```

Using `PjFreeze`:

```
use MaciejSz\PjFreeze\PjFreeze;

$data = new \stdClass();
$data->recursion = $data; // circular reference

$Freeze = new PjFreeze();

$serializedObj = $Freeze->serialize($data)->jsonSerialize();
$jp_freeze_encoded = json_encode($serializedObj);
echo json_last_error_msg(); // "No error"

$unserializedObj = json_decode($jp_freeze_encoded);
$unserialized = $Freeze->unserialize($unserializedObj);
assert($unserialized->recursion === $unserialized);
```

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

[](#installation)

Via composer:

```
composer require maciej-sz/pj-freeze

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

2

Last Release

3597d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/39b57a9d10ac98e2b35734480a240ebf517ce97fd6f5e421bc30666d2874e144?d=identicon)[maciej-sz](/maintainers/maciej-sz)

---

Top Contributors

[![maciej-sz](https://avatars.githubusercontent.com/u/1526148?v=4)](https://github.com/maciej-sz "maciej-sz (33 commits)")

---

Tags

jsonserializedeserialize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maciej-sz-pj-freeze/health.svg)

```
[![Health](https://phpackages.com/badges/maciej-sz-pj-freeze/health.svg)](https://phpackages.com/packages/maciej-sz-pj-freeze)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k504.8M164](/packages/mtdowling-jmespathphp)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30525.1M53](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15882.2M30](/packages/clue-ndjson-react)[zumba/json-serializer

Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.

130784.7k15](/packages/zumba-json-serializer)[ergebnis/json-printer

Provides a JSON printer, allowing for flexible indentation.

9141.0M29](/packages/ergebnis-json-printer)[ergebnis/json-normalizer

Provides generic and vendor-specific normalizers for normalizing JSON documents.

8240.3M8](/packages/ergebnis-json-normalizer)

PHPackages © 2026

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