PHPackages                             belt/matter - 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. belt/matter

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

belt/matter
===========

Proper object traversal

v0.1(11y ago)2253BSD-2-ClausePHPPHP &gt;=5.4.0

Since Oct 25Pushed 11y ago1 watchersCompare

[ Source](https://github.com/beltphp/matter)[ Packagist](https://packagist.org/packages/belt/matter)[ Docs](https://github.com/beltphp/matter)[ RSS](/packages/belt-matter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Belt.`Matter`
=============

[](#beltmatter)

[![Latest Version](https://camo.githubusercontent.com/80f4fa069afb87580d21015d882d0441f29832dae8e66013ba359c57e5313be2/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656c742f6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/beltphp/matter/releases)[![Software License](https://camo.githubusercontent.com/c5a67f4ed7839698b87147f1932d7c9a0b2545d5229c428d459bbe4f3017bcb5/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62656c742f6d61747465722e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/85a1a911c3524fc74b713fa16638c320aed8ea6b6dcdcfd821ceb144a83afdd9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62656c747068702f6d61747465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/beltphp/releases)[![Coverage Status](https://camo.githubusercontent.com/e9dc3e01848cf4cb1392a9d3e7a74dfd5b37cbbe0983babf0bc955888d120dd8/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f62656c747068702f6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/beltphp/matter/code-structure)[![Quality Score](https://camo.githubusercontent.com/201a6dc4020820be3c241a2f37059c2f5c587da8c7bbc6fdb44b4287501cfabf/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62656c747068702f6d61747465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/beltphp/matter/)

> Proper object traversal

Belt.`Matter` is an utility library that makes working with JSON objects a bit (actually a lot) more pleasant. It converts JSON strings, objects or arrays to a proper tree structure that can be traversed without warnings or errors.

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

[](#installation)

Via Composer.

```
$ composer require belt/matter
```

Usage
-----

[](#usage)

When we use JSON in PHP, we usually have to use the properties of the JSON object. This is really nice and all, but it doesn't work when a property does not exist.

```
$object = json_decode('{"foo":"bar","bar":[1, 2, 3, 4]","baz":"lorem ipsum"}');
$object->foo;       // "bar"
$object->something; // BOOM!
```

Well, that's not really nice, is it? We have to put guards around everytime we want to use a property.

This is where Matter comes in handy!

```
// Before
$object = json_decode('{"foo":"bar"}');
$object->foo;       // "bar"
$object->something; // BOOM!

// After
use Belt\Matter;

$object = Matter::fromJson('{"foo":"bar"}');
$object->get('foo')->get();         // "bar"
$object->get('something')->get();   // null
```

What Matter does for you, is convert a given JSON string or value into a tree structure. This allows you to request nodes from the tree without being afraid of errors/warnings that are thrown.

You can always access any value in the JSON object.

```
$object = Matter::fromJson('{"foo":[1, 2, 3, 4],"bar":"lorem"}');
$object->get('foo')->get(0)->get(); // 1
$object->get('foo')->get(4)->get(); // null
$object->get('bar')->get();         // "lorem"

$object = Matter::fromJson('[{"name":"Alice"},{"name":"Bob"}]');
$object->get(0)->get('name')->get(); // "Alice"
$object->get(1)->get('name')->get(); // "Bob"
$object->get(2)->get('name')->get(); // null
```

Each Matter node also implements `ArrayAccess` and `Iterator`, which allows you to work even faster!

```
$users = Matter::fromJson('[{"name":"Alice"},{"name":"Bob"}]');
$users[0]['name']->get(); // "Alice"
$users[1]['name']->get(); // "Bob"
$users[2]['name']->get(); // null

foreach ($users as $user) {
    $name = $user['name']->get();
}
```

Additionally, you can also safely access properties of the object without having to use get to retrieve the property node.

```
$object = Matter::fromJson('{"foo":{"bar":{"baz":42}}}');
$object->foo->bar->baz->get(); // 42
$object->baz->bar->foo->get(); // null
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/beltphp/matter/blob/master/CONTRIBUTING.md).

License
-------

[](#license)

Please see [LICENSE](https://github.com/beltphp/matter/blob/master/LICENSE).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

4223d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c742d9a971e721439dab6897fa61e24052b4433845900a52480f66b90160793?d=identicon)[belt](/maintainers/belt)

---

Top Contributors

[![kleiram](https://avatars.githubusercontent.com/u/323498?v=4)](https://github.com/kleiram "kleiram (10 commits)")

---

Tags

jsontreetoolkit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/belt-matter/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

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

15267.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

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