PHPackages                             flexible-labs/json-store - 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. [Database &amp; ORM](/categories/database)
4. /
5. flexible-labs/json-store

ActiveLibrary[Database &amp; ORM](/categories/database)

flexible-labs/json-store
========================

Laravel-friendly JSON store with dot notation, auto-save, file locking, and TTL support.

v1.2.3(1y ago)115MITPHPCI passing

Since Apr 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/flexible-labs/JsonStore)[ Packagist](https://packagist.org/packages/flexible-labs/json-store)[ RSS](/packages/flexible-labs-json-store/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

📦 JsonStore
===========

[](#-jsonstore)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/ffc60c351b9753550ad5a7fe492434041ec6f74e5a07ef1c8bde684d6576cfc9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c657869626c652d6c6162732f6a736f6e2d73746f72652e737667)](https://packagist.org/packages/flexible-labs/json-store)[![Laravel](https://camo.githubusercontent.com/93554d1ac44e7880097a6bd117e99f90c33ddf03dcf0a37f3047fa50b8aaa4d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d726564)](https://camo.githubusercontent.com/93554d1ac44e7880097a6bd117e99f90c33ddf03dcf0a37f3047fa50b8aaa4d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422d726564)[![PHP](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)[![Downloads](https://camo.githubusercontent.com/aeb87c2351645ebfe5ddfed37bd6739d0e396898fe3561e6678201ac05873a31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c657869626c652d6c6162732f6a736f6e2d73746f7265)](https://camo.githubusercontent.com/aeb87c2351645ebfe5ddfed37bd6739d0e396898fe3561e6678201ac05873a31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c657869626c652d6c6162732f6a736f6e2d73746f7265)

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Key Features](#key-features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [API Reference](#api-reference)
- [Key Features](#key-features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Detailed Usage](#detailed-usage)
    - [Creating a Store](#creating-a-store)
    - [Setting and Retrieving Data](#setting-and-retrieving-data)
    - [Managing Arrays](#managing-arrays)
    - [Caching with TTL](#caching-with-ttl)
    - [Concurrency Handling](#concurrency-handling)
    - [Additional API Methods](#additional-api-methods)
- [Practical Examples](#practical-examples)
- [Testing](#testing)
- [Advanced Tips](#advanced-tips)
- [Comparison with Other Tools](#comparison-with-other-tools)
- [License](#license)
- [Author](#author)

Introduction
------------

[](#introduction)

**JsonStore** is a Laravel-friendly package that simplifies JSON-based storage. It enables you to store, retrieve, and manage structured data with ease using dot-notation, automatic persistence, caching, and file-locking mechanisms.

---

Key Features
------------

[](#key-features)

- **Dot Notation:** Intuitively access and modify deeply nested JSON keys.
- **Automatic Saving:** Changes are persisted without manual `save()` calls.
- **Safe Concurrency:** File-level locking prevents race conditions.
- **TTL Caching:** Built-in `remember()` helper for temporary data storage.
- **Flexible Storage:** Works with any disk, base path, or multi-tenancy setup.

---

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

[](#installation)

```
composer require flexible-labs/json-store
```

---

Configuration
-------------

[](#configuration)

```
php artisan vendor:publish --provider="FlexibleLabs\JsonStore\JsonStoreServiceProvider"
```

```
return [
    'disk'      => env('JSONSTORE_DISK', 'local'),
    'base_path' => env('JSONSTORE_BASE', ''),
];
```

---

Quick Start
-----------

[](#quick-start)

```
use FlexibleLabs\JsonStore\JsonStore;

Route::get('/quick-start', function () {
    $store = JsonStore::make('settings.json');
    $store->set('theme', 'dark');
    return $store->get();
});
```

---

API Reference
-------------

[](#api-reference)

MethodDescription`make(filename, default = [], disk = null, base = null)`Create a new JsonStore instance.`disk(disk)`Set the storage disk.`base(path)`Set the base path inside the disk.`load()`Load the JSON file (auto-called on access).`save()`Manually save changes to the JSON file.`set(key, value)`Set a value by key (dot notation supported).`get(key = null, default = null, asObject = false)`Get a value or all data.`getOrSet(key, default)`Get value or set it if missing.`has(key)`Check if a key exists.`forget(key)`Remove a key.`delete(key, default = null)`Delete and return a value.`deleteFrom(key, valueToRemove)`Remove an item from an array.`insert(keyOrValue, value = null)`Append to array or to root.`replace(array)`Replace all data.`update(array)`Merge updates into current data.`remember(key, ttl, callback)`Cache value with TTL.`withLock(callback, deleteLockAfter = true)`Safely run operations with a file lock.`exists()`Check if the file exists.---

Detailed Usage
--------------

[](#detailed-usage)

### Creating a Store

[](#creating-a-store)

```
$store = JsonStore::make('config.json', ['theme' => 'light']);
$store = JsonStore::make('config.json')->disk('public')->base('configs');
```

### Setting and Retrieving Data

[](#setting-and-retrieving-data)

```
$store->set('app.name', 'LaravelApp');
$store->set('app.version', '11.0');
$appName = $store->get('app.name');
$full = $store->get();
```

### Managing Arrays

[](#managing-arrays)

```
// Append a user to an array
$store->insert('users', 'John Doe');

// Remove a specific value from an array
$store->deleteFrom('users', 'John Doe');

// Replace the entire store content (use with caution)
$store->replace([
    'theme' => 'blue',
    'notifications' => ['email' => true, 'sms' => false]
]);

// Recursively update part of the data without overriding the rest
$store->update([
    'notifications' => ['push' => true],
    'app' => ['name' => 'Json Manager']
]);
```

### Caching with TTL

[](#caching-with-ttl)

```
$cached = $store->remember('api.response', 3600, fn () => Http::get(...)->json());
```

### Concurrency Handling

[](#concurrency-handling)

```
$store->withLock(function () use ($store) {
    $views = $store->get('views', 0);
    $store->set('views', $views + 1);
});
```

### Additional API Methods

[](#additional-api-methods)

#### `getOrSet()`

[](#getorset)

```
$token = $store->getOrSet('auth.token', fn () => Str::uuid());
```

#### `forget()`

[](#forget)

```
$store->forget('deprecated.key');
```

#### `delete()`

[](#delete)

```
$value = $store->delete('temp.value');
```

#### `has()`

[](#has)

```
if ($store->has('env.debug')) {
    // Do something
}
```

#### `exists()`

[](#exists)

```
if ($store->exists()) {
    // File exists in storage
}
```

#### `all()` via `get()`

[](#all-via-get)

```
$data = $store->get();
```

#### `set()` with array

[](#set-with-array)

```
$store->set([
    'key1' => 'value1',
    'nested.key' => 'value2'
]);
```

#### `insert()` directly to root

[](#insert-directly-to-root)

```
$store->insert('a new root item');
```

---

Practical Examples
------------------

[](#practical-examples)

### Dynamic Routes

[](#dynamic-routes)

```
Route::get('/articles/{id}', function ($id) {
    $store = JsonStore::make("{$id}.json")->disk('public')->base('articles');
    return $store->exists() ? $store->get() : abort(404);
});
```

### Nested JSON Manipulation

[](#nested-json-manipulation)

```
$store = JsonStore::make('colors.json');
$store->set('1.name', 'red');
$store->set('1.code', '#ff0000');
return $store->get();
```

---

Testing
-------

[](#testing)

```
composer install
composer test
```

---

Advanced Tips
-------------

[](#advanced-tips)

- Integrate with Laravel Echo for real-time sync.
- Use environment-specific `disk`/`base` for separation.
- Schedule regular exports via Laravel scheduler.

---

Comparison with Other Tools
---------------------------

[](#comparison-with-other-tools)

FeatureJsonStoreLaravel SettingsLaravel JSON SettingsDot notation✅✅✅Auto persistence✅❌❌File locking✅❌❌TTL caching✅❌❌Flexible paths✅❌✅Native Laravel feel✅✅✅---

License
-------

[](#license)

JsonStore is open-source software licensed under the **MIT license**.

---

Author
------

[](#author)

Maintained by [Suleiman Shahbari](https://github.com/suliemandev).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

7

Last Release

401d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/72cb98ec90d9f9c7b9a7d98ff96405c26089764e8c3e81890859f5721242a916?d=identicon)[Suleiman](/maintainers/Suleiman)

---

Top Contributors

[![suliemandev](https://avatars.githubusercontent.com/u/13323859?v=4)](https://github.com/suliemandev "suliemandev (24 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flexible-labs-json-store/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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