{"id":20678900,"url":"https://github.com/phpgt/json","last_synced_at":"2025-04-13T18:35:10.416Z","repository":{"id":47542775,"uuid":"330728532","full_name":"phpgt/Json","owner":"phpgt","description":"Structured, type-safe, immutable JSON objects, and schema validation.","archived":false,"fork":false,"pushed_at":"2025-03-01T16:29:45.000Z","size":228,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T06:00:02.900Z","etag":null,"topics":["data-transfer-object","json","json-schema","web-standards"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["phpgt"]}},"created_at":"2021-01-18T16:44:25.000Z","updated_at":"2025-03-01T16:29:48.000Z","dependencies_parsed_at":"2024-11-16T21:25:37.758Z","dependency_job_id":"1fefb01c-30de-46c9-a5ce-3a65726afc5a","html_url":"https://github.com/phpgt/Json","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"26b3972a9d95b8d7d2985841f3b69d8876fc7c38"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FJson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FJson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FJson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FJson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/Json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761271,"owners_count":21157523,"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":["data-transfer-object","json","json-schema","web-standards"],"created_at":"2024-11-16T21:22:59.388Z","updated_at":"2025-04-13T18:35:10.397Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"readme":"Structured, type-safe, immutable JSON objects. \n==============================================\n\nBuilt on top of [PHP.Gt/DataObject][dataobject], this repository adds JSON-specific compatibility. The main usage will be via the `JsonObjectBuilder` class that can be used to build a type of `JsonObject` from a JSON string or decoded JSON object (from `json_decode`).\n\nThe purpose of using these classes to represent decoded JSON data is to provide a type-safe, immutable interface to the enclosed data.\n\n***\n\n\u003ca href=\"https://giub.com/PhpGt/Json/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/json-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codacy.com/gh/PhpGt/Json\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/json-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/PhpGt/Json\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/json-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/Json\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/json-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.php.gt/json\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/json-docs.svg\" alt=\"PHP.Gt/Json documentation\" /\u003e\n\u003c/a\u003e\n\nThe abstract `JsonObject` class extends the [`DataObject` base class][dataobject] to represent the root element of a JSON object. In JSON, this may not necessarily be a key-value-pair object.\n\nThe following JSON strings can all be successfully decoded:\n\n+ `{\"type\": \"key-value-pair\"}` - a typical key-value-pair object\n+ `[{\"name\": \"first\"}, {\"name\": \"second\"}` - an array of objects\n+ `0` - an integer\n+ `1.05` - a floating point\n+ `false` - a boolean\n+ `\"Today is going to be a good day\"` - a string\n+ `null` - a null\n\nBecause of this, the base `DataObject` would be unable to represent the different types of scalar value in a type-safe way. The `JsonObjectBuilder` class returns a new instance of the abstract `JsonObject` class which is one of the following types:\n\n+ `JsonKvpObject` - identical features to `DataObject` with type-safe getters for its keys\n+ `JsonPrimitive` - a representation of the primitive value, further broken down into types `JsonArrayPrimitive`, `JsonBoolPrimitive`, `JsonFloatPrimitive`, `JsonIntPrimitive`, `JsonNullPrimitive` and `JsonStringPrimitive`.\n\nUsage example\n-------------\n\n```php\nuse Gt\\Json\\JsonObjectBuilder;\nuse Gt\\Json\\JsonKvpObject;\nuse Gt\\Json\\JsonPrimitive\\JsonPrimitive;\n\n$response = file_get_contents(\"https://example.com/details.json\");\n$builder = new JsonObjectBuilder();\n$jsonObject = $builder-\u003efromJsonString($response);\n\nif($jsonObject instanceof JsonKvpObject) {\n\t$id = $jsonObject-\u003egetInt(\"id\");\n}\nelseif($jsonObject instanceof JsonPrimitive) {\n\t$id = $jsonObject-\u003egetPrimitiveValue();\n}\n\necho \"Requested ID is: $id\";\n```\n\nFetch API\n---------\n\nCheck out the [PHP implementation of the Fetch API][fetch] that uses this library to work with JSON endpoints asynchronously.\n\n[dataobject]: https://www.php.gt/dataobject\n[fetch]: https://www.php.gt/fetch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fjson/lists"}