PHPackages                             paysera/lib-object-wrapper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. paysera/lib-object-wrapper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

paysera/lib-object-wrapper
==========================

Wrapper around JSON-decoded data that lets easily get structured items

0.4.1(9mo ago)121.5k8[3 PRs](https://github.com/paysera/lib-object-wrapper/pulls)2PHPPHP ^7.1 || ^8.0

Since Oct 10Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/paysera/lib-object-wrapper)[ Packagist](https://packagist.org/packages/paysera/lib-object-wrapper)[ RSS](/packages/paysera-lib-object-wrapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (11)Used By (2)

ObjectWrapper
=============

[](#objectwrapper)

This library provides class that lets easily get structured items from JSON-decoded data.

Why?
----

[](#why)

So that it would be easier and quicker to:

- check correct data types. This allows to use PHP7 static type-hints easily;
- check required keys/items;
- give defaults to missing items;
- provide information about exact place in object tree where the data fails your requirements.

Usage
-----

[](#usage)

```
$jsonString = json_encode([
    // ...
]);
/** @var stdClass $jsonData */
$jsonData = json_decode($jsonString);

$data = new ObjectWrapper($jsonData);

// Use like an associative array if needed
foreach ($data as $key => $value) {
    var_dump(isset($data[$value]));
    var_dump($data[$value]);
}

var_dump($data['non_existing']);    // just null - no notice

var_dump($data->getRequired('required_key'));   // throws exception if missing

var_dump($data->getString('key_with_string'));  // throws exception if not string, defaults to null
var_dump($data->getString('key_with_string', 'default'));  // different default
var_dump($data->getRequiredString('key_with_string'));  // throws exception if missing or not string

var_dump(get_class($data->getRequiredObject('inner_data'))); // always another ObjectWrapper instance
var_dump(get_class($data->getObject('inner_data'))); // another ObjectWrapper instance or null

var_dump($data->getArrayOfString('keys'));    // array of strings
var_dump($data->getArrayOfOject('children')); // array of ObjectWrapper instances

try {
    $data->getRequiredObject('inner_data')->getArrayOfObject('list')[0]->getRequiredString('key');
} catch (MissingItemException $e) {
    echo $e->getMessage(); // Missing required key "inner_data.list.0.key"
    echo $e->getKey();     // inner_data.list.0.key
}
```

Methods
-------

[](#methods)

- `$data[$key]` - use array accessor to get any value inside, returns `null` if it's unavailable. If value is object, instance of `ObjectWrapper` will be returned;
- `getRequired`. Returns mixed value, but checks that it is provided;
- `getRequiredBool`. Returns `bool`;
- `getBool`. Returns `bool` or `null`;
- `getRequiredFloat`. Returns `float`. Accepts `int`, but casts it to `float`;
- `getFloat`. Returns `float` or `null`. Accepts `int`, but casts it to `float`;
- `getRequiredInt`. Returns `int`;
- `getInt`. Returns `int` or `null`;
- `getRequiredObject`. Returns another `ObjectWrapper` instance;
- `getObject`. Returns another `ObjectWrapper` instance or `null`;
- `getRequiredString`. Returns `string`;
- `getString`. Returns `string` or `null`;
- `getArray`. Returns `array`. If no item is provided, returns empty array, so no `getRequiredArray` is available;
- `getArrayOfBool`. Returns `array`, all it's items are `bool` (or it's empty);
- `getArrayOfFloat`. Returns `array`, all it's items are `float` (or it's empty);
- `getArrayOfInt`. Returns `array`, all it's items are `int` (or it's empty);
- `getArrayOfString`. Returns `array`, all it's items are `string` (or it's empty);
- `getArrayOfObject`. Returns `array`, all it's items are instances of `ObjectWrapper` (or it's empty).
- `getDataAsArray`. Returns `array`, all it's items are `array` or primitive types.
- `getOriginalData`. Returns `stdClass`, the original data passed to constructor.

Some things to keep in mind
---------------------------

[](#some-things-to-keep-in-mind)

- `stdClass` is used for objects - this is default for `json_decode`. This is to easily check where the data was an object and where it was an array. For example, if empty object or empty array is passed as JSON and you denormalize to an array, there is no way to check what was the type of original data;
- `null` values are treated the same as it would not be provided at all:
    - it will not throw `InvalidItemTypeException` if you provide `null` and some type was expected (even array or object);
    - it will throw `MissingItemException` even if you provide the value but it is `null`;
- the object cannot be modified - setting or unsetting anything is not supported.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance55

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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

Recently: every ~529 days

Total

9

Last Release

299d ago

PHP version history (3 changes)0.1.0PHP ^7.0

0.3.0PHP ^7.0 || ^8.0

0.4.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d385187c2b529d5c1189dfc3763972f76738d24293593ff3db876fff82321db?d=identicon)[paysera.com](/maintainers/paysera.com)

---

Top Contributors

[![mariusbalcytis](https://avatars.githubusercontent.com/u/1590072?v=4)](https://github.com/mariusbalcytis "mariusbalcytis (3 commits)")[![vbartusevicius](https://avatars.githubusercontent.com/u/7325630?v=4)](https://github.com/vbartusevicius "vbartusevicius (3 commits)")[![borilyordanov](https://avatars.githubusercontent.com/u/11679283?v=4)](https://github.com/borilyordanov "borilyordanov (2 commits)")[![PayseraGithub](https://avatars.githubusercontent.com/u/73477610?v=4)](https://github.com/PayseraGithub "PayseraGithub (1 commits)")[![pelanis](https://avatars.githubusercontent.com/u/31431703?v=4)](https://github.com/pelanis "pelanis (1 commits)")[![zbpopova9292](https://avatars.githubusercontent.com/u/91263908?v=4)](https://github.com/zbpopova9292 "zbpopova9292 (1 commits)")[![donatascn](https://avatars.githubusercontent.com/u/23005654?v=4)](https://github.com/donatascn "donatascn (1 commits)")[![mSprunskas](https://avatars.githubusercontent.com/u/4427922?v=4)](https://github.com/mSprunskas "mSprunskas (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paysera-lib-object-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/paysera-lib-object-wrapper/health.svg)](https://phpackages.com/packages/paysera-lib-object-wrapper)
```

PHPackages © 2026

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