{"id":16409564,"url":"https://github.com/pointybeard/helpers-functions-json","last_synced_at":"2026-05-18T05:06:35.923Z","repository":{"id":57043215,"uuid":"190879405","full_name":"pointybeard/helpers-functions-json","owner":"pointybeard","description":"A collection of functions for working with JSON files and strings","archived":false,"fork":false,"pushed_at":"2019-06-08T11:22:29.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T16:27:29.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pointybeard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-08T11:22:03.000Z","updated_at":"2019-06-08T11:22:25.000Z","dependencies_parsed_at":"2022-08-23T23:40:25.365Z","dependency_job_id":null,"html_url":"https://github.com/pointybeard/helpers-functions-json","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointybeard%2Fhelpers-functions-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointybeard%2Fhelpers-functions-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointybeard%2Fhelpers-functions-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointybeard%2Fhelpers-functions-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pointybeard","download_url":"https://codeload.github.com/pointybeard/helpers-functions-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240405385,"owners_count":19796181,"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":[],"created_at":"2024-10-11T06:20:25.669Z","updated_at":"2026-05-18T05:06:35.866Z","avatar_url":"https://github.com/pointybeard.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Helpers: JSON Functions\n\n-   Version: v1.0.0\n-   Date: June 08 2019\n-   [Release notes](https://github.com/pointybeard/helpers-functions-json/blob/master/CHANGELOG.md)\n-   [GitHub repository](https://github.com/pointybeard/helpers-functions-json)\n\nA collection of functions for working with JSON files and strings\n\n## Installation\n\nThis library is installed via [Composer](http://getcomposer.org/). To install, use `composer require pointybeard/helpers-functions-json` or add `\"pointybeard/helpers-functions-json\": \"~1.0.0\"` to your `composer.json` file.\n\nAnd run composer to update your dependencies:\n\n    $ curl -s http://getcomposer.org/installer | php\n    $ php composer.phar update\n\n### Requirements\n\nThis library makes use of the [PHP Helpers: Flags Functions](https://github.com/pointybeard/helpers-functions-falgs) (`pointybeard/helpers-functions-flags`). It is installed automatically via composer.\n\nTo include all the [PHP Helpers](https://github.com/pointybeard/helpers) packages on your project, use `composer require pointybeard/helpers`.\n\n## Usage\n\nThis library is a collection convenience function for common tasks relating to working with JSON strings and documents. They are included by the vendor autoloader automatically. The functions have a namespace of `pointybeard\\Helpers\\Functions\\Json`\n\nThe following functions are provided:\n\n-   `json_validate`\n-   `json_validate_file`\n-   `json_decode_file`\n\nExample usage:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\ninclude __DIR__.'/vendor/autoload.php';\n\nuse pointybeard\\Helpers\\Functions\\Json;\n\n/* Example 1: Check if valid string is valid JSON **/\nvar_dump(Json\\json_validate('{\"person\": {\"name\": \"Sarah Smith\"}}'));\n// bool(true)\n\n/** Example 2: Check if invalid string is valid JSON **/\n$isValid = Json\\json_validate('{\"person\": {\"name\":}', $code, $message);\nvar_dump($isValid, $code, $message);\n// bool(false)\n// int(4)\n// string(12) \"Syntax error\"\n\n/** Example 3: Check if file contains valid JSON **/\n$tmp = tempnam(sys_get_temp_dir(), 'JsonFunctionTest');\nfile_put_contents($tmp, '{\"person\": {\"name\": \"Sarah Smith\"}}');\nvar_dump(Json\\json_validate_file($tmp));\n// bool(true)\n\n/* Example 4: Decode contents of valid JSON file **/\nvar_dump(Json\\json_decode_file($tmp));\n// class stdClass#2 (1) {\n//   public $person =\u003e\n//   class stdClass#3 (1) {\n//     public $name =\u003e\n//     string(11) \"Sarah Smith\"\n//   }\n// }\n\n/* Example 5: Validate file containing invalid JSON **/\nfile_put_contents($tmp, '{\"person\": {\"name\": {\"name\": \"Broken JSON}');\n$isValid = Json\\json_validate_file($tmp, $code, $message);\nvar_dump($isValid, $code, $message);\n// bool(false)\n// int(3)\n// string(53) \"Control character error, possibly incorrectly encoded\"\n\n/* Example 6: Attempt to decode file containing invalid JSON **/\ntry {\n    var_dump(Json\\json_decode_file($tmp));\n} catch (JsonException $ex) {\n    echo $ex-\u003egetMessage().PHP_EOL;\n}\n// Control character error, possibly incorrectly encoded\n\n/** Example 7: Attempt to validate non-existent JSON file **/\n$isValid = Json\\json_validate_file('nonexistent/file.json', $code, $message);\nvar_dump($isValid, $code, $message);\n// bool(false)\n// NULL\n// string(42) \"File nonexistent/file.json is not readable\"\n\n/* Example 8: Attempt to decode non-existent JSON file **/\nJson\\json_decode_file('nonexistent/file.json');\n// Fatal error: Uncaught JsonException: The file nonexistent/file.json is not readable in /path/to/helpers-functions-json/src/Json/Json.php on line 82\n\n```\n\n## Support\n\nIf you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/pointybeard/helpers-functions-json/issues),\nor better yet, fork the library and submit a pull request.\n\n## Contributing\n\nWe encourage you to contribute to this project. Please check out the [Contributing documentation](https://github.com/pointybeard/helpers-functions-json/blob/master/CONTRIBUTING.md) for guidelines about how to get involved.\n\n## License\n\n\"PHP Helpers: JSON Functions\" is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointybeard%2Fhelpers-functions-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpointybeard%2Fhelpers-functions-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointybeard%2Fhelpers-functions-json/lists"}