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

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

pyther/json
===========

A lightweight (de)serializer between json strings and data models.

v0.2.5(1y ago)043MITPHPPHP &gt;=8.1

Since Aug 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/peterGdot/Pyther.Json)[ Packagist](https://packagist.org/packages/pyther/json)[ RSS](/packages/pyther-json/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)DependenciesVersions (9)Used By (0)

Pyther.Json
===========

[](#pytherjson)

A lightweight (de)serializer between json strings and data models with the following features:

- support for nested arrays and objects
- pre defined or custom naming policies
- support for basic or backed enumerations.
- meta/attribute support for
    - property renaming
    - property exclusion
    - (array) data type
    - datetime format
    - enum format
- several settings like
    - include protected properties
    - skip null values
    - skip empty arrays
    - skip inherited properties
    - enum format (name, value or full)
    - and more ...
- takes documentation "@var" hints into account
- no external dependencies
- straightforward to use

Requirements:

- PHP 8.1+

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

[](#installation)

Install the [Composer Package](https://packagist.org/packages/pyther/json)

`composer require pyther/json`

Examples:
---------

[](#examples)

### Deserialization

[](#deserialization)

```
    // creates a new order class and populate its properties from a json string or array.
    $order = Json::deserialize($json, Order::class);
```

### Serialization

[](#serialization)

```
    // creates a json string populate from orders properties.
    $json = Json::serialize($order);
```

### Optional Settings

[](#optional-settings)

```
$settings = new JsonSettings();

// set optional naming policy, default is none (json attrbiutes equals object attribute names).
// supported policies: CamelToPascalNamingPolicy, CamelToSnakeNamingPolicy, CamelToKebabNamingPolicy, PascalToCamelNamingPolicy
$settings->setNamingPolicy(new CamelToPascalNamingPolicy());

// Disable json indention (enabled by default).
$settings->setPrettyPrint(false);

// Enable or disable to serialize DateTime as string (enabled by default).
$settings->setDateTimeAsString(false);

// Set the default date time format (\DateTime::W3C by default).
// This can be overwriten per Property using "#[JsonDateTime(...)]"
$settings->setDateTimeFormat(\DateTime::W3C)

// Defines the default serialization format for enumerations (EnumFormat::Value by default).
// This can be overridden using the "JsonEnum" meta tag.
// values are: EnumFormat::Value, EnumFormat::Name, EnumFormat::Full
$settings->setEnumFormat(EnumFormat::Value)

// Define to skip null values (false by default).
$settings->setSkipNull(true);

// Define to skip empty arrays (false by defaut).
$settings->setSkipEmptyArray(true);

// Set to true, to include protected members (false by default).
$settings->setIncludeProtected(true)

// Define to skip inherited properties (false by default).
$settings->setSkipInheritedProperties(true);

$json = Json::serialize($order, $settings);
```

Enums
-----

[](#enums)

```
enum Status : int {
    case Inactive = 0;
    case Active = 1;
}
```

### EnumFormat::Name

[](#enumformatname)

```
class EnumTest {
    #[JsonEnum(EnumFormat::Name)]
    public Status $status;
}

// or set global for all enums
$settings->setEnumFormat(EnumFormat::Name);
```

Result:

```
{
    "Status": "Active"
}
```

### EnumFormat::Value

[](#enumformatvalue)

```
class EnumTest {
    #[JsonEnum(EnumFormat::Value)]
    public Status $status;
}

// or set global for all enums
$settings->setEnumFormat(EnumFormat::Value);
```

Result:

```
{
    "Status": 1
}
```

### EnumFormat::Full

[](#enumformatfull)

```
class EnumTest {
    #[JsonEnum(EnumFormat::Full)]
    public Status $status;
}

// or set global for all enums
$settings->setEnumFormat(EnumFormat::Full);
```

Result:

```
{
    "Status": {
        "Name": "Active",
        "Value": 1
    }
}
```

Meta/Attributes
---------------

[](#metaattributes)

### Json

[](#json)

The attribute allows to manually match a single property with a json attribute. This attribute will ignore the selected naming policy.

```
use Pyther\Json\Attributes\Json;

class MyClass
{
    // fill the "sku" from the json "id" property.
    #[Json("id)]
    public string $sku;
}
```

### JsonIgnore

[](#jsonignore)

Allows to ignore a single property during serialization, deserialization or both.

```
use Pyther\Json\Attributes\JsonIgnore;

class MyClass
{
    // ignore on serialization and deserialization
    #[JsonIgnore]
    public string $ignoreMe;

    // ignore on serialization only
    #[JsonIgnore(true, false)]
    public string $ignoreMe;

    // ignore on deserialization only
    #[JsonIgnore(false, true)]
    public string $ignoreMe;
}
```

### JsonType

[](#jsontype)

Defines a datatype for a single property. This is especially useful for arrays due the lack of type hint support for arrays in php.

```
use Pyther\Json\Attributes\JsonType;

class MyClass
{
    // definfes the type of the array items.
    #[JsonType(OrderItem::class)]
    public array $typedArrayByMeta;

    // possible to replace the missing build in datatype.
    #[JsonType(\int::class)]
    public $intByMeta;
}
```

### JsonDateTime

[](#jsondatetime)

Allows to define a date/time format for a single property.

```
use Pyther\Json\Attributes\JsonDateTime;

class MyClass
{
    // parse this property by the given format.
    #[JsonDateTime("d/m/Y")]
    public string $dayOfBirth;
}
```

### JsonEnum

[](#jsonenum)

Allows to define the enum serialization format for a single property.

```
use Pyther\Json\Attributes\JsonEnum;

class MyClass
{
    // parse this property by the given format.
    #[JsonEnum(EnumFormat::Name)]
    public Status $status;
}
```

### JsonComplete

[](#jsoncomplete)

Allows a post process when the object and all child objects are ready.

```
use Pyther\Json\Attributes\JsonComplete;

class MyClass
{
    // ...

    // Any parameterless function with any name you want.
    #[JsonComplete]
    public function onComplete() {
        // $this is fully parsed and ready to use here
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance46

Moderate activity, may be stable

Popularity8

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

Every ~35 days

Recently: every ~59 days

Total

8

Last Release

410d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.2

v0.1.1PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/904a2f429f6b7e47ef87a331a8266be72a7e15970c2e0e28f8a257c2efbcb711?d=identicon)[peterGdot](/maintainers/peterGdot)

---

Top Contributors

[![peterGdot](https://avatars.githubusercontent.com/u/124894114?v=4)](https://github.com/peterGdot "peterGdot (15 commits)")

---

Tags

jsonphp-libraryserializationjsonserializemodeldeserialize

### Embed Badge

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

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

###  Alternatives

[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[zumba/json-serializer

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

129743.7k13](/packages/zumba-json-serializer)[ergebnis/json-printer

Provides a JSON printer, allowing for flexible indentation.

9138.2M24](/packages/ergebnis-json-printer)[ergebnis/json-normalizer

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

8237.5M6](/packages/ergebnis-json-normalizer)[ergebnis/json-pointer

Provides an abstraction of a JSON pointer.

2021.8M6](/packages/ergebnis-json-pointer)[pmjones/throwable-properties

Copies properties of a Throwable to a serializable object.

1554.7k2](/packages/pmjones-throwable-properties)

PHPackages © 2026

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