PHPackages                             walter-a-jablonowski/json-db - 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. walter-a-jablonowski/json-db

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

walter-a-jablonowski/json-db
============================

Minimal JSON db that uses file sys folders and files

00PHP

Since Aug 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/walter-a-jablonowski/json-db)[ Packagist](https://packagist.org/packages/walter-a-jablonowski/json-db)[ RSS](/packages/walter-a-jablonowski-json-db/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Json DB
=======

[](#json-db)

**Minimal JSON db that uses file sys folders and files**

***currently in dev***

recently ... done just for fun in coffee breaks while working on more important weekend projects;-)

```
composer update

```

Concepts
--------

[](#concepts)

We ignore the fact that information in file system is organized in files, folders and in this case json keys. Instead we handle all as one big logical tree of information. File and folder names are hierarchical keys that just continue within json files as json keys.

Information is accessed by a ˋhierarchical.keyˋ. The library will take care of what needs to be loaded.

So we don't need to deal with how information is organised, we can just use it. If you save new information the library will use a standard behaviour to determine where it should be saved (see below). If you want to have control over the structure in the file system yourself, the only thing you need to do is make some folders and emtpy json files. The library will use existing files. Usage is quite intuitive: `$data = $db->query('things.some_thing')`.

**Read**

When key is-&gt;query() will loadjson keypart of filefilefull filedirall json files in that folder merged**Write**

save() will split the given key in parts like ˋfolder.part.file-part.json.partˋ. It looks for existing folders and file that might already have data. Behaviour is

When key hasand json is-&gt;save() willexisting json key (1)merge data under keyexisting file name (1)merge data in fileexisting dir onlyobject (2)forbidden cause file name missingexisting dir onlyarraysplit data in single files (numeric name)existing dir &amp; more keysuse first key behind dir as filenamenon-existing key (3) (4)make a new folder and file from keyComments

- (1) If it has more keys, these will be used as json keys
- (2) Similar javascript: object = an array with string keys, array = array with numeric keys
- (3) If you want use some of the keys as json keys call ensureFolder() frist TASK or ensureFile()?
- (4) If you want split an array in multiple files use a loop and call ˋ-&gt;save()ˋ multiple times

DEV

- Do we have a del files func? or just folder?

Usage
-----

[](#usage)

```
$db = new JsonDB('some/db');

$data = $db->query('things.some.thing')

  ->filter( fn($v, $k) => floatval($v['price']) < 50.0 )
  ->sort( fn($a, $b) => // uses uasort()
      $a['price'] == $b['price'] ? 0 :
      $a['price'] <  $b['price'] ? -1 : 1
    )
  ->get();

foreach( $data as $rec )
  var_dump( $rec );

// Save

$db->save('0.someval', 'myval');

// Join stuff: a join is just a loop joining 2 arrays
```

**Alternatives:** ,

Advanced
--------

[](#advanced)

maybe ...

- When a file contains array and we save obj, we might need solve this in some way
- get('first') get(idx) saves some methods: no first()
- save('first') save(idx)
- delete('last') delete(idx)
- We could add a method that returns a new "sub-db" for queried information, that can be filtered again e.g. in loops
- Finish delete()
- Add more file types, rename the project - fwd from this
    - plain text is also data available under a key
    - yml files
    - md files
    - images
    - ...
- maybe implement has()
- maybe also load subfolders when my/folder/\*

this currently is an undefined behaviour

- folder with json subkeys alone could mean del in all files (no subkey for file just folder)

LICENSE
-------

[](#license)

Copyright (C) Walter A. Jablonowski 2021, MIT [License](LICENSE)

Licenses of third party software used in samples see [credits](credits.md).

[Privacy](https://walter-a-jablonowski.github.io/privacy.html) | [Legal](https://walter-a-jablonowski.github.io/imprint.html)

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a980a80c3b5dd7599e7de6ef9a627b5187590d2fcf99e818770ae5dffee92d46?d=identicon)[walterjab](/maintainers/walterjab)

---

Top Contributors

[![walter-a-jablonowski](https://avatars.githubusercontent.com/u/31986246?v=4)](https://github.com/walter-a-jablonowski "walter-a-jablonowski (15 commits)")

### Embed Badge

![Health badge](/badges/walter-a-jablonowski-json-db/health.svg)

```
[![Health](https://phpackages.com/badges/walter-a-jablonowski-json-db/health.svg)](https://phpackages.com/packages/walter-a-jablonowski-json-db)
```

###  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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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