Summary
This release introduces the JSONManager class, a PHP utility for managing JSON files with comprehensive CRUD operations, sorting, pagination, merging, backup, and restore functionalities.
Key Features
- Static Methods: All methods are now static for easier usage without instantiation.
- Create, Update, Find, Delete: Comprehensive operations for manipulating JSON data.
- Count, Sort, Paginate: Utilities to manage and navigate through JSON data efficiently.
- Merge: Combine data from other JSON files or arrays seamlessly.
- Backup and Restore: Safeguard data integrity with backup and restore capabilities.
Usage Examples
Create a New Object
<?php
require_once 'JsonManager.php'; // Assuming your class file is named JsonManager.php
$path = 'data.json';
$newObject = [
'id' => 1,
'name' => 'John Doe',
'age' => 30,
'city' => 'New York'
];
try {
// Save the new object under 'users' without updating existing data
JsonManager::save($path, $newObject, false, 'users');
echo "New object saved successfully!";
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
Update an Existing Object
<?php
require_once 'JsonManager.php'; // Assuming your class file is named JsonManager.php
$path = 'data.json';
$updatedObject = [
'id' => 1,
'name' => 'John Doe',
'age' => 31,
'city' => 'Los Angeles'
];
try {
// Update the existing object where 'id' equals 1 under 'users'
JsonManager::save($path, $updatedObject, true, 'users', 'id', 1);
echo "Object with ID 1 updated successfully!";
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
Additional Notes
- This release streamlines JSON data management by offering static methods for direct access and usability.
- Future enhancements may include advanced querying and performance optimizations.
Full Changelog: GitHub Commit History