PHPackages                             021/api-entity - 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. 021/api-entity

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

021/api-entity
==============

Quickly and conveniently interpret JSON data into PHP classes

v2.1.3(8mo ago)13732MITPHPPHP &gt;=8.1 &lt;8.4CI passing

Since Feb 5Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/021-projects/api-entity)[ Packagist](https://packagist.org/packages/021/api-entity)[ RSS](/packages/021-api-entity/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (2)

It's even easier to develop SDKs for your APIs
==============================================

[](#its-even-easier-to-develop-sdks-for-your-apis)

[![Latest Stable Version](https://camo.githubusercontent.com/f8b0f71311f764b899d4e0519e146bb7d8d2199e3c9179da599950f71d0e3a2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f3032312f6170692d656e74697479)](https://packagist.org/packages/021/api-entity)[![run-tests](https://github.com/021-projects/api-entity/actions/workflows/run-tests.yml/badge.svg)](https://github.com/021-projects/api-entity/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/011e1b4233c0a3b3ede4c9260a89dc513712f1f51634a494445b460cc46f664e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f3032312f6170692d656e74697479)](https://packagist.org/packages/021/api-entity)[![License](https://camo.githubusercontent.com/6e46d27134431161ad7bee6edf2df7dd27c61e03ebdf817e448094a6b5f543db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f3032312f6170692d656e74697479)](https://packagist.org/packages/021/api-entity)

This package allows you to quickly and conveniently interpret JSON data into PHP classes.

Support
-------

[](#support)

If you like this package, you can support me by donating some cryptocurrency:

#### Bitcoin

[](#bitcoin)

1G4U12A7VVVaUrmj4KmNt4C5SaDmCXuW49

#### Litecoin

[](#litecoin)

LXjysogo9AHiNE7AnUm4zjprDzCCWVESai

#### Ethereum

[](#ethereum)

0xd23B42D0A84aB51a264953f1a9c9A393c5Ffe4A1

#### Tron

[](#tron)

TWEcfzu2UAPsbotZJh8DrEpvdZGho79jTg

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

[](#installation)

You can install the package via composer:

```
composer require 021/api-entity
```

Usage
-----

[](#usage)

### After 2.1

[](#after-21)

2.1 version introduces an automatically casts parsing from phpdoc. You can use `@property` and `@property-read` annotations to define property types.

```
use O21\ApiEntity\BaseEntity;
use O21\ApiEntity\Casts\Getter;
use SDK\Entities\UserProfile; // Your custom class
use SDK\Entities\UserPet; // Your custom class

use function O21\ApiEntity\Response\json_props;

/**
 * Class User
 * @package SDK\Entities
 *
 * @property int $id
 * @property string $firstName
 * @property string $lastName
 * @property \Carbon\Carbon $registerAt
 * @property UserProfile $profile
 * @property \Illuminate\Support\Collection $pets
 * @property-read string $fullName
 */
class User extends BaseEntity
{
    public function fullName(): Getter
    {
        return Getter::make(fn() => $this->firstName.' '.$this->lastName);
    }
}

/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $api->get('/user/1');

// Get decoded JSON array from response
// which is a PSR-7 response or JSON string
$props = json_props($response);
// Create User object from JSON props
$user = new User($props);

// Or just pass response to BaseEntity constructor
$user = new User($response);

echo $user->fullName; // John Doe
echo $user->full_name; // John Doe
echo $user->registerAt->format('Y-m-d H:i:s'); // 2022-01-01 00:00:00
echo $user->profile->phone; // +1234567890
echo $user->pets->first()->name; // Archy
```

### Before 2.1

[](#before-21)

```
use O21\ApiEntity\BaseEntity;
use O21\ApiEntity\Casts\Getter;
use SDK\Entities\UserProfile; // Your custom class
use SDK\Entities\UserPet; // Your custom class

use function O21\ApiEntity\Response\json_props;

/**
 * Class User
 * @package SDK\Entities
 *
 * @property int $id
 * @property string $firstName
 * @property string $lastName
 * @property \Carbon\Carbon $registerAt
 * @property UserProfile $profile
 * @property \Illuminate\Support\Collection $pets
 * @property-read string $fullName
 */
class User extends BaseEntity
{
    protected array $casts = [
        'registerAt' => 'datetime',
        'profile' => UserProfile::class,
        'pets' => 'collection:'.UserPet::class,
    ];

    public function fullName(): Getter
    {
        return Getter::make(fn() => $this->firstName.' '.$this->lastName);
    }
}

/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $api->get('/user/1');

// Get decoded JSON array from response
// which is a PSR-7 response or JSON string
$props = json_props($response);
// Create User object from JSON props
$user = new User($props);

// Or just pass response to BaseEntity constructor
$user = new User($response);

echo $user->fullName; // John Doe
echo $user->full_name; // John Doe
echo $user->registerAt->format('Y-m-d H:i:s'); // 2022-01-01 00:00:00
echo $user->profile->phone; // +1234567890
echo $user->pets->first()->name; // Archy
```

Check tests/Entities for more examples.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance59

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

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

Recently: every ~126 days

Total

9

Last Release

262d ago

Major Versions

v1.1.0 → v2.0.02024-02-23

PHP version history (3 changes)v1.0.0PHP &gt;=8.0

v1.0.1PHP &gt;=8.0 &lt;8.4

v2.0.0PHP &gt;=8.1 &lt;8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/850e7a3d7b73d4aca00b33bfd13c33b97a8bec35d3b889d50cc0eec3b26eb337?d=identicon)[021-projects](/maintainers/021-projects)

---

Top Contributors

[![021-projects](https://avatars.githubusercontent.com/u/20326979?v=4)](https://github.com/021-projects "021-projects (22 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/021-api-entity/health.svg)

```
[![Health](https://phpackages.com/badges/021-api-entity/health.svg)](https://phpackages.com/packages/021-api-entity)
```

###  Alternatives

[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[ultrono/laravel-sitemap

Sitemap generator for Laravel 11, 12 and 13

36412.6k6](/packages/ultrono-laravel-sitemap)[mischasigtermans/laravel-toon

Token-Optimized Object Notation encoder/decoder for Laravel with intelligent nested object handling

13113.1k](/packages/mischasigtermans-laravel-toon)[dniccum/nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.

37116.4k](/packages/dniccum-nova-documentation)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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