A lightweight, zero-dependency PHP class to use JSON files as a robust NoSQL database.
Need a simple database but don't want the overhead of setting up MySQL/PostgreSQL? php-json-db-manager turns any simple JSON file into a fully queryable NoSQL database with strict error handling, built-in lock mechanisms for concurrency, and a fluent query interface.
- Zero Configuration: Just point it to a
.jsonfile and start querying. - Fluent API: Chainable methods for intuitive data manipulation (
where(),insert(),update(), etc.). - Concurrency Safe: Utilizes
flock()under the hood to ensure safe read/writes during simultaneous requests. - Incredibly Fast: Entirely loaded into memory for lightning-fast reads on small to medium datasets.
Include via Composer (if published) or drop the class directly into your project.
composer require ranaahmar/php-json-db-manager(Or simply copy src/JsonDB.php into your /lib folder).
require 'vendor/autoload.php';
// Or include directly: require 'src/JsonDB.php';
use Ahmar\Database\JsonDB;
// Initialize it (will create 'users.json' if it does not exist)
$db = new JsonDB('users.json');
// 1. Insert Data
$db->insert([
'id' => 1,
'name' => 'Ahmar Hussain',
'role' => 'admin'
]);
// 2. Fetch Data
$users = $db->all();
echo json_encode($users);Retrieve items where a specific key matches a value.
$admins = $db->find('role', 'admin');Finds records matching $key = $value and merges $newData into those records.
$db->update('id', 1, [
'role' => 'superadmin'
]);Deletes records that match the criteria.
$db->delete('id', 1);Wipes the entire database back to an empty array.
$db->truncate();Contributions, issues, and feature requests are welcome!
This project is MIT licensed. See LICENSE.
If you found this tool useful, check out our other high-performance web utilities and follow Ahmar Hussain for more open-source excellence.
- Stackaura Hub - The central index for all 100 repositories.
- Free LLM APIs - A curated list of zero-cost AI endpoints.
- Awesome MCP Servers - The ultimate collection of Model Context Protocol implementations.
- System Design Cheatsheet - Master complex architectures in minutes.
- Next.js SaaS Starter - The fastest way to launch your next product.
- Website: stackaura.com
- LinkedIn: Ahmar Hussain
- Facebook: Ahmar Hussain
- GitHub: @RanaAhmar