jsondbphp / jsondb
JsonDB: Lightweight Document Container for Modern PHP Apps.
Fund package maintenance!
codewithsushil
ashishkumbhar01
Patreon
Open Collective
Buy Me A Coffee
paypal.me/codewithsushil
Requires
- php: ^8.2
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- laravel/pint: ^1.22
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.2
- symfony/var-dumper: ^7.3
This package is auto-updated.
Last update: 2025-06-28 11:24:51 UTC
README
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.
- 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
composer require jsondbphp/jsondb
Example
- First create a folder
data
. - Create a
users.json
file inside of data folder.
<?php require("vendor/autoload.php"); use Json\Database\JsonDB; // Create DB instance $db = new JsonDB(__DIR__ . '/data'); // Insert $db->insert('users', [ 'name' => 'Alice', 'email' => 'alice@example.com' ]);