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

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

lnear/json
==========

Lightweight JSON wrapper for PHP

0.0.2(1y ago)011MITPHPPHP ^8.1

Since Jun 3Pushed 1y agoCompare

[ Source](https://github.com/lnear-dev/JSONObject)[ Packagist](https://packagist.org/packages/lnear/json)[ Docs](https://github.com/lnear-dev/JSONObject)[ RSS](/packages/lnear-json/feed)WikiDiscussions main Synced 1mo ago

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

JSONObject Library
==================

[](#jsonobject-library)

This package provides a robust abstraction for handling JSON objects in PHP. It includes functionalities for loading, saving, and manipulating JSON data with a fluent API.

Features
--------

[](#features)

- Load and save JSON data.
- Access and modify JSON data using array syntax.
- Push, prepend, and merge data into JSON objects.
- Filter, map, reduce, and sort JSON data.
- Increment and decrement numeric values.
- Convert JSON objects to and from JSON strings.
- Fluent API for chaining method calls.

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

[](#installation)

You can install the package via composer:

```
composer require lnear/json
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Lame\JSONFile;

// Instantiate JSONFile with a file path
$jsonFile = new JSONFile('/path/to/file.json');

// Access and manipulate JSON data
$jsonFile->put('key', 'value');
$jsonFile->save(); // Save changes to the file

// Load JSON data from the file
$data = $jsonFile->load();
```

### JSONString

[](#jsonstring)

The `JSONString` class handles JSON data stored as a string. It also extends the `JSONObject` abstract class and provides methods to work with JSON data in string format.

### Usage

[](#usage-1)

```
use Lame\JSONString;

// Instantiate JSONString with a JSON string
$jsonString = new JSONString('{"key": "value"}');

// Access and manipulate JSON data
$jsonString->put('newKey', 'newValue');
$jsonString->save(); // Save changes to the JSON string

// Load JSON data from the string
$data = $jsonString->load();
```

Exception Handling
------------------

[](#exception-handling)

Both classes handle exceptions related to JSON parsing and file operations. They throw appropriate exceptions when errors occur, allowing you to handle them gracefully in your application.

### ArrayAccess and Countable

[](#arrayaccess-and-countable)

```
if ($jsonObject->has('name')) {
    echo $jsonObject['name']; // Outputs: John
}

$jsonObject['email'] = 'john.doe@example.com';
unset($jsonObject['age']);
echo count($jsonObject); // Outputs the count of items in the JSON object
```

### Data Manipulation

[](#data-manipulation)

```
$jsonObject->push('tags', 'developer');
$jsonObject->prepend('tags', 'programmer');
$jsonObject->increment('age', 2);
$jsonObject->decrement('age', 1);

$allData = $jsonObject->all();
$filteredData = $jsonObject->filter(fn($key, $value) => is_string($value));
```

### Advanced Methods

[](#advanced-methods)

```
$keysStartingWithA = $jsonObject->startingWith('a');
$jsonObject->forget('location');
$jsonObject->flush();
$jsonObject->flushStartingWith('temp_');

$jsonObject->each(fn($key, $value) => print("Key: $key, Value: $value"));
$mappedData = $jsonObject->map(fn($value) => strtoupper($value));
$reducedData = $jsonObject->reduce(fn($carry, $value) => $carry . $value, '');
$sortedData = $jsonObject->sort(fn($a, $b) => $a  $b);
$reversedData = $jsonObject->reverse();
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](https://github.com/lnear-dev/JSONObject/blob/main/LICENSE) file for details.

Documentation
-------------

[](#documentation)

For detailed documentation, please visit [JSONObject Documentation](https://docs.lnear.dev/json).

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

[](#contributing)

We welcome contributions! Please read our [Contributing Guidelines](https://github.com/lnear-dev/JSONObject/blob/main/CONTRIBUTING.md) before making any contributions.

Contact
-------

[](#contact)

If you have any questions or feedback, feel free to reach out at .

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Lanre Waju](https://github.com/oplanre)
- [All Contributors](../../contributors)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Total

2

Last Release

713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/27f2f0c5d47c596274bba2fb2d20f5a02854b8b3f06557d98ada60bd3f46ebba?d=identicon)[lnear](/maintainers/lnear)

---

Top Contributors

[![oplanre](https://avatars.githubusercontent.com/u/113967437?v=4)](https://github.com/oplanre "oplanre (5 commits)")

---

Tags

phpjson

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[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)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

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