An open API service indexing awesome lists of open source software.

https://github.com/codewithsushil/json-db

JSON DB for APIs Testing and minimalist project
https://github.com/codewithsushil/json-db

json-api json-database json-db json-server

Last synced: 2 months ago
JSON representation

JSON DB for APIs Testing and minimalist project

Awesome Lists containing this project

README

          

![JsonDB](/art/jsondb.png)

[![Tests](https://github.com/CodeWithSushil/json-db/actions/workflows/tests.yml/badge.svg)](https://github.com/CodeWithSushil/json-db/actions/workflows/tests.yml)
![Packagist Version](https://img.shields.io/packagist/v/jsondbphp/jsondb?style=flat&logo=composer&logoColor=%23fff)
![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/jsondbphp/jsondb/php?style=flat&logo=php&logoColor=blue&label=PHP&color=blue)
![Packagist License](https://img.shields.io/packagist/l/jsondbphp/Jsondb?style=flat&label=License&color=blue)
![Packagist Downloads](https://img.shields.io/packagist/dt/jsondbphp/Jsondb?style=flat&label=Downloads&color=blue)
![Packagist Stars](https://img.shields.io/packagist/stars/jsondbphp/jsondb?style=flat&logo=packagist&logoColor=%23ffffff&label=%F0%9F%8C%9F%20Stars)

**JsonDB** is a lightweight, document-oriented NoSQL-style database written in PHP. It provides a simple, file-based alternative to traditional databases by storing and managing data as structured JSON files. JsonDB is perfect for lightweight apps, prototyping, local storage, and embedded tools where a full-fledged database system is unnecessary.

---

## ๐Ÿš€ Features

- โšก **Zero-Config:** No database server or setup neededโ€”just PHP and your filesystem.
- ๐Ÿงฉ **Document-Based:** Each collection is a JSON file; each record is a structured JSON document.
- ๐Ÿงช **CRUD Operations:** Easy-to-use API for create, read, update, and delete operations.
- ๐Ÿ•ต๏ธโ€โ™‚๏ธ **Search & Filter:** Built-in query capabilities using associative arrays and conditions.
- [x] Coming soon
- ๐Ÿ” **JWT & Session Authentication:** Secure API with optional login/auth guard.
- ๐ŸŒ **REST API Wrapper:** JSON RESTful interface for HTTP clients.
- ๐Ÿ—ƒ๏ธ **Transactions & Atomic Writes:** Prevents data corruption with locking mechanisms.
- ๐Ÿ” **Replication & Backup Support:** Optional add-ons for syncing and restoring data.
- ๐Ÿงฐ **CLI Tools:** Perform operations via command line using Symfony Console.
- ๐Ÿง  **In-memory Caching:** Fast reads with optional caching for large JSON datasets.
- ๐Ÿงพ **Indexing (Planned):** For quicker lookups and searches on large datasets.

---

## ๐Ÿ“ฆ Why Use JsonDB?

- โœ… **Simple:** No external dependencies, DB servers, or complex setup.
- โœ… **Portable:** Just include it in your projectโ€”works anywhere PHP runs.
- โœ… **Human-Readable:** JSON files are easy to read, edit, version-control, and debug.
- โœ… **Great for Prototyping:** Ideal for testing APIs, local apps, and building offline tools.
- โœ… **Customizable:** Built in modern PHP (PHP 8.4+), uses OOP, Traits, Enums, and Interfaces.

---

## ๐Ÿ’ก Use Cases

- ๐Ÿ”ง Rapid API Prototyping
- ๐Ÿ—ƒ Offline Data Storage
- ๐Ÿงช Test Mock Databases
- ๐Ÿ›  Configuration/Settings Store
- ๐ŸŽฎ Game Save/State Files
- ๐ŸŒ Lightweight Backend for SPA/JS apps
- ๐Ÿ’ป CLI Data Manipulation Tools

---

## ๐Ÿง‘โ€๐Ÿ’ป How It Works

#### Install

```bash
composer require jsondbphp/jsondb
```

#### Example

- First create a folder `data`.
- Create a `users.json` file inside of data folder.

```php
insert('users', [
'name' => 'Alice',
'email' => 'alice@example.com'
]);

// findAll
$result = $db->findAll('users');
print_r($resull);

// find
$result = $db->find('users', 'name');
print_r($result);

// update
$db->update('users', 'name', 'Alice');

// delete
$db->delete('users', 'name');

```

---