{"id":22213791,"url":"https://github.com/damir-sijakovic/jsondb","last_synced_at":"2026-04-30T17:31:53.770Z","repository":{"id":135104627,"uuid":"596839283","full_name":"damir-sijakovic/jsonDb","owner":"damir-sijakovic","description":"Simple file key/value database utility function.","archived":false,"fork":false,"pushed_at":"2024-03-14T20:09:38.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T06:26:26.678Z","etag":null,"topics":["json","json-database","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damir-sijakovic.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-03T03:04:23.000Z","updated_at":"2023-02-03T03:06:18.000Z","dependencies_parsed_at":"2024-03-14T21:31:01.314Z","dependency_job_id":"b948b13f-9300-4190-86cd-049c6325f408","html_url":"https://github.com/damir-sijakovic/jsonDb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/damir-sijakovic/jsonDb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damir-sijakovic%2FjsonDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damir-sijakovic%2FjsonDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damir-sijakovic%2FjsonDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damir-sijakovic%2FjsonDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damir-sijakovic","download_url":"https://codeload.github.com/damir-sijakovic/jsonDb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damir-sijakovic%2FjsonDb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32472396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","json-database","php"],"created_at":"2024-12-02T21:11:17.328Z","updated_at":"2026-04-30T17:31:53.751Z","avatar_url":"https://github.com/damir-sijakovic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonDb \n\n## Overview\n\nThe `JsonDb` class provides a simple interface for storing and retrieving data in a JSON file, acting as a lightweight database. It allows for basic CRUD (Create, Read, Update, Delete) operations on the JSON data.\n\n## Usage\n\n### Initialization\n\nTo use the `JsonDb` class, first include it in your PHP script and instantiate it with the path to the JSON file you want to use as your database.\n\n```php\nrequire_once 'JsonDb.php';\n$db = new JsonDb(\"path/to/yourfile.json\");\n```\n\n### Methods\n\n#### `__construct($fileName)`\n\n- **Description**: Constructor method; initializes the JsonDb instance with the specified file name.\n- **Parameters**:\n  - `$fileName`: Path to the JSON file to be used as a database.\n- **Returns**: An instance of the JsonDb class.\n\n#### `get($key = null)`\n\n- **Description**: Retrieves the value associated with a specific key from the JSON file. If no key is provided, it returns the entire data array.\n- **Parameters**:\n  - `$key`: (Optional) The key of the value to retrieve.\n- **Returns**: The value associated with the specified key, or the entire data array if no key is provided. Returns `null` if the file does not exist or the key is not found.\n\n#### `set($key, $value)`\n\n- **Description**: Sets the value for a specific key in the JSON file. If the key already exists, the value is updated. If the key does not exist, it is created.\n- **Parameters**:\n  - `$key`: The key to set or update in the file.\n  - `$value`: The value to associate with the key.\n- **Returns**: `true` on success, or `false` on failure.\n\n#### `delete($key)`\n\n- **Description**: Deletes a key-value pair from the JSON file.\n- **Parameters**:\n  - `$key`: The key of the value to delete.\n- **Returns**: `true` if the key was successfully deleted, or `false` if the key does not exist or the file could not be updated.\n\n## Private Methods\n\nThese methods are used internally by the class and are not intended to be used directly.\n\n#### `getFileContents()`\n\n- **Description**: Retrieves the contents of the JSON file.\n- **Returns**: The contents of the file as a string, or `null` if the file does not exist.\n\n#### `decodeJson($jsonData)`\n\n- **Description**: Decodes a JSON string into an associative array.\n- **Parameters**:\n  - `$jsonData`: The JSON string to decode.\n- **Returns**: The decoded JSON as an associative array, or `null` on error.\n\n## Examples\n\n### Reading Data\n\n```php\n// Get all data\n$data = $db-\u003eget();\nprint_r($data);\n\n// Get data by key\n$value = $db-\u003eget('someKey');\necho \"Value: $value\\n\";\n```\n\n### Writing Data\n\n```php\n// Set a new value\nif ($db-\u003eset('newKey', 'newValue')) {\n    echo \"Data saved successfully.\\n\";\n}\n```\n\n### Deleting Data\n\n```php\n// Delete a key-value pair\nif ($db-\u003edelete('keyToRemove')) {\n    echo \"Key removed successfully.\\n\";\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamir-sijakovic%2Fjsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamir-sijakovic%2Fjsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamir-sijakovic%2Fjsondb/lists"}