PHPackages                             mindplay/jsondoc - 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. mindplay/jsondoc

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

mindplay/jsondoc
================

JSON-based object/document store

0.11.0(10y ago)526LGPL-3.0+PHPPHP &gt;=5.3.0

Since May 3Pushed 10y ago2 watchersCompare

[ Source](https://github.com/mindplay-dk/jsondoc)[ Packagist](https://packagist.org/packages/mindplay/jsondoc)[ RSS](/packages/mindplay-jsondoc/feed)WikiDiscussions master Synced 2mo ago

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

mindplay/jsondoc
================

[](#mindplayjsondoc)

Simple, file-based object/document-database using JSON-files for persistence.

[![Build Status](https://camo.githubusercontent.com/502d7c113ca8ea3ba90613458f38964896eb42839bfe5fb4839ba47b09052c95/68747470733a2f2f7472617669732d63692e6f72672f6d696e64706c61792d646b2f6a736f6e646f632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mindplay-dk/jsondoc)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3ef5fe56d39d09aabaffe0e646cd7c722d779a256042ba3eea4622b0615dc302/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696e64706c61792d646b2f6a736f6e646f632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mindplay-dk/jsondoc/?branch=master)

[![Code Coverage](https://camo.githubusercontent.com/0bc9461e329acf4d57bf0536d0f00ca53d74ef42d0bd9a905ce5c0d427c1f52a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696e64706c61792d646b2f6a736f6e646f632f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mindplay-dk/jsondoc/?branch=master)

Overview
--------

[](#overview)

Object-graphs are serialized and stored as JSON-documents, in individual files - the JSON representations are (optionally, by default) indented and formatted in a human-readable and CVS-friendly way.

Object-keys map directly to folders and file-names - for example, an object stored as `foo/bar` is saved as `{database name}/foo/bar.json`.

Write and delete-operations are committed using basic transaction semantics, with simple database-level locking to prevent simultaneous writes, using early error-detection and automatic roll-back on failure.

Please see "Limitations" below for additional technical details.

API
---

[](#api)

The API consists of two classes:

`DocumentStore` represents the "connection" to a data-store: a root-folder containing one or more databases.

`DocumentSession` represents a session with one specific database inside a data-store - it manages the loading and saving of objects, and attempts to do so in a transactional and safe manner, e.g. committing all save/delete operations atomically.

Usage
-----

[](#usage)

Create a DocumentStore with FilePersistence and point it to an existing folder:

```
$store = new DocumentStore(new FilePersistence($db_path));

```

Ask the DocumentStore to create a DocumentSession:

```
$session = $store->openSession();

```

This will lock the store in shared mode, until you `close()` the session. (it will also automatically close if it falls out of scope.)

Now create objects of any class, and store them:

```
$a = new Foo;
$a->bar = 'Hello, World.';

$session->store($a, 'foo/bar');

```

Note that the state of the object has been captured in-memory, but the serialized object does not get written to underlying storage until changes are committed.

Alternatively, you can store an object with a generated UUID under a parent ID:

```
$a = new Foo;
$a->bar = 'Hello again!';

$id = $session->append($a, 'foo', $uuid);

var_dump($uuid); // "029d97a2-7676-45b1-9d49-353bec0d71c0"
var_dump($id);   // "foo/029d97a2-7676-45b1-9d49-353bec0d71c0"

```

Load objects from the database into the current session:

```
$b = $session->load('foo/baz');

```

Delete unwanted objects:

```
$session->delete('foo/baz');

```

Call `commit()` to persist all the pending store/delete-operations:

```
$session->commit();

```

Finally, you should `close()` to explicitly release the lock:

```
$session->close();

```

The `DocumentSession` API also provides a few other operations:

- `exists($id)` indicates whether a document with the given ID exists in the store.
- `contains($id)` indicates whether the session contains a document with a given ID.
- `getId($object)` provides the document ID of an object in the session.
- `evict($id)` evicts the object/document with the given ID from the session.
- `flush()` evicts all objects/documents and pending operations from the session.

Limitations
-----------

[](#limitations)

Using individual, flat files for data-storage is *not fast* - this library (by design) is optimized for consistent storage, quick and easy implementation, human-readable and VCS-compatible file-based storage, in applications where speed is not a critical factor.

The JsonSerializer itself has an important limitation: it is designed to store self-contained object-graphs only - it does not support shared or circular object-references. This is by design, and in-tune with good DDD design practices: an object-graph with shared or circular references does not have clear transaction boundaries and cannot be stored in a predictable and consistent way.

This library does not synthesize object keys - which means you must assign a key when you store a new object. Again, this is by design.

More detailed background on limitations and technical decisions [here](http://stackoverflow.com/questions/10489876).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

3996d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9445f567f43ee7a963270651e40e533634586f959e4df3d5398d001b1cb49be8?d=identicon)[mindplay.dk](/maintainers/mindplay.dk)

---

Top Contributors

[![mindplay-dk](https://avatars.githubusercontent.com/u/103348?v=4)](https://github.com/mindplay-dk "mindplay-dk (38 commits)")

### Embed Badge

![Health badge](/badges/mindplay-jsondoc/health.svg)

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

###  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)
