PHPackages                             diamond-dove/simple-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. diamond-dove/simple-json

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

diamond-dove/simple-json
========================

Read and write big JSON files

v2.0.0(12mo ago)3191[2 issues](https://github.com/diamond-dove/simple-json/issues)MITPHPPHP ^8.4

Since Feb 12Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/diamond-dove/simple-json)[ Packagist](https://packagist.org/packages/diamond-dove/simple-json)[ Docs](https://github.com/diamond-dove/simple-json)[ RSS](/packages/diamond-dove-simple-json/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

Simple JSON File Reader and Writer
==================================

[](#simple-json-file-reader-and-writer)

This package makes it easy to read and write simple JSON files. It uses generators to minimize memory usage, even when dealing with large files.

Here is an example of how to read a JSON file:

```
use DiamondDove\SimpleJson\SimpleJsonReader;

SimpleJsonReader::create('users.json')->get()
   ->each(function(array $user) {
        // process the row
    });
```

Installation
============

[](#installation)

You can install the package using composer:

```
composer require diamon-dove/simple-json

```

Usage
=====

[](#usage)

Reading a JSON
--------------

[](#reading-a-json)

Suppose you have a JSON file with the following content:

```
[
  {"email":  "john@example.com", "first_name":  "John"},
  {"email":  "jane@example.com", "first_name":  "jane"}
]
```

To read this file in PHP, you can do the following:

```
use DiamondDove\SimpleJson\SimpleJsonReader;

// $records is an instance of Illuminate\Support\LazyCollection
$records = SimpleJsonReader::create($pathToJson)->get();

$records->each(function(array $user) {
   // in the first pass $user will contain
   // ['email' => 'john@example.com', 'first_name' => 'john']
});
```

### Working with LazyCollections

[](#working-with-lazycollections)

`get` will return an instance of `Illuminate\Support\LazyCollection`. This class is part of the Laravel framework. Behind the scenes generators are used, so memory usage will be low, even for large files.

You'll find a list of methods you can use on a `LazyCollection` [in the Laravel documentation.](https://laravel.com/docs/master/collections#the-enumerable-contract)

Here's a quick, silly example where we only want to process rows that have a first\_name that contains more than 5 characters. You'll find a list of methods you can use on a LazyCollection in the Laravel documentation.

Here's a quick, silly example where we only want to process elements that have a first\_name that contains more than 5 characters.

```
SimpleJsonReader::create($pathToJson)->get()
->filter(function(array $user) {
return strlen($user['first_name']) > 5;
})
->each(function(array $user) {
// processing user
});
```

Writing files
-------------

[](#writing-files)

To write a JSON file, you can use the following code:

use DiamondDove\\SimpleJson\\SimpleJsonWriter;

```
$writer = SimpleJsonWriter::create($pathToJson)
->push([[
'first_name' => 'John',
'last_name' => 'Doe',
],
[
'first_name' => 'Jane',
'last_name' => 'Doe',
]
]);
```

The file at pathToJson will contain:

```
[
  {"first_name": "John", "last_name": "Doe"},
  {"first_name":  "Jane", "last_name":  "Doe"}
]
```

You can also use:

```
SimpleJsonWriter::create($this->pathToJson)
                        ->push([
                            'name'  => 'Thomas',
                            'state' => 'Nigeria',
                            'age'   => 22,
                        ])
                        ->push([
                            'name'  => 'Luis',
                            'state' => 'Nigeria',
                            'age'   => 32,
                        ]);
```

Testing
=======

[](#testing)

```
composer test
```

Contributing
============

[](#contributing)

Please see [CONTRIBUTING](https://github.com/diamond-dove/simple-json/blob/main/CONTRIBUTING.md) for details.

Security
========

[](#security)

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

Credits
=======

[](#credits)

- [Fermin Perdomo](https://github.com/masterfermin02)
- [All Contributors](../../contributors)

License
=======

[](#license)

The MIT License [(MIT)](LICENSE.md). Please see License File for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~409 days

Total

4

Last Release

364d ago

Major Versions

v1.0.2 → v2.0.02025-06-24

PHP version history (3 changes)v1.0.0PHP ^8.0|^8.1

v1.0.1PHP ^8.0

v2.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/17c416be607cbb47c55e76e115e3c35c3d74906ff422e808e4bba3be1dfb5cd6?d=identicon)[masterfermin02](/maintainers/masterfermin02)

---

Top Contributors

[![masterfermin02](https://avatars.githubusercontent.com/u/4625540?v=4)](https://github.com/masterfermin02 "masterfermin02 (8 commits)")[![elminson](https://avatars.githubusercontent.com/u/2476286?v=4)](https://github.com/elminson "elminson (1 commits)")

---

Tags

diamond-dovesimple-json

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/diamond-dove-simple-json/health.svg)

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

###  Alternatives

[spatie/laravel-settings

Store your application settings

1.5k6.8M135](/packages/spatie-laravel-settings)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9348.3M267](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10533.5M989](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.4M362](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.5M132](/packages/illuminate-cookie)

PHPackages © 2026

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