{"id":20187958,"url":"https://github.com/commonphp/config-json","last_synced_at":"2025-06-14T15:32:38.303Z","repository":{"id":223025380,"uuid":"758791039","full_name":"commonphp/config-json","owner":"commonphp","description":"Enables applications to load and save configurations in JSON format, leveraging the CommonPHP Driver Management system for seamless integration.","archived":false,"fork":false,"pushed_at":"2024-02-18T14:45:13.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-13T18:24:33.372Z","etag":null,"topics":["commonphp","configuration-management","json-configuration","json-driver","open-source","php-json"],"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/commonphp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-02-17T04:55:55.000Z","updated_at":"2024-02-17T18:35:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3974d91-7d61-42f1-9c1b-6e70f93612af","html_url":"https://github.com/commonphp/config-json","commit_stats":null,"previous_names":["commonphp/config-json"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonphp%2Fconfig-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonphp%2Fconfig-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonphp%2Fconfig-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonphp%2Fconfig-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commonphp","download_url":"https://codeload.github.com/commonphp/config-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241622613,"owners_count":19992504,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["commonphp","configuration-management","json-configuration","json-driver","open-source","php-json"],"created_at":"2024-11-14T03:26:48.027Z","updated_at":"2025-03-03T07:12:26.410Z","avatar_url":"https://github.com/commonphp.png","language":"PHP","readme":"# JSON Configuration Driver for CommonPHP\n\nThis library provides a JSON configuration driver, `JsonConfigurationDriver`, which implements the `ConfigurationDriverContract` from the CommonPHP Configuration Management library. It enables applications to load and save configurations in JSON format, leveraging the CommonPHP Driver Management system for seamless integration.\n\n## Features\n\n- **Load JSON Configurations**: Effortlessly read and decode JSON files into associative arrays.\n- **Save Configurations as JSON**: Serialize and save PHP associative arrays back into JSON format files.\n- **JSON Validation**: Ensures the integrity of the JSON content during the loading process.\n- **Exception Handling**: Comprehensive error and exception handling for common JSON parsing issues.\n\n## Installation\n\nUse Composer to install the Configuration Manager and this driver:\n\n```\ncomposer require comphp/config\ncomposer require comphp/config-json\n```\n\n## Usage\n\nFirst, ensure that your `DriverManager` instance is configured to recognize the JSON driver:\n\n```php\nuse CommonPHP\\Drivers\\DriverManager;\nuse CommonPHP\\Configuration\\Drivers\\JsonConfigurationDriver\\JsonConfigurationDriver;\n\n$driverManager = new DriverManager();\n$driverManager-\u003eenable(JsonConfigurationDriver::class);\n```\n\nThen, when using the Configuration Manager to load or save a JSON file, the `JsonConfigurationDriver` will automatically be utilized for `.json` extensions, thanks to the `#[ConfigurationDriverAttribute('json')]` attribute.\n\n### Loading a Configuration File\n\n```php\n$configManager-\u003eloadDriver(JsonConfigurationDriver::class);\n$config = $configManager-\u003eget('path/to/configuration.json');\n```\n\n### Saving a Configuration File\n\nEnsure the driver has been loaded as shown above, then:\n\n```php\n$config-\u003edata['newKey'] = 'newValue';\n$config-\u003esave(); // Saves the modifications back to 'path/to/configuration.json'\n```\n\n## Exception Handling\n\n- **JsonException**: Thrown if the JSON file contains invalid JSON.\n- **Exception**: General exceptions for file read/write failures or JSON decoding issues.\n\nThis driver provides a simple yet powerful means to work with JSON-based configurations within the CommonPHP framework, ensuring flexibility and ease of use for developers.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonphp%2Fconfig-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommonphp%2Fconfig-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonphp%2Fconfig-json/lists"}