{"id":23302412,"url":"https://github.com/skrtdev/json2","last_synced_at":"2025-08-22T07:32:23.813Z","repository":{"id":57052717,"uuid":"369824119","full_name":"skrtdev/json2","owner":"skrtdev","description":"JSON2 converts json and arrays in structured classes","archived":false,"fork":false,"pushed_at":"2022-04-01T15:55:40.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T02:46:56.309Z","etag":null,"topics":["class","hacktoberfest","json","mapper","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/skrtdev.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}},"created_at":"2021-05-22T14:08:56.000Z","updated_at":"2021-10-01T11:53:07.000Z","dependencies_parsed_at":"2022-08-24T05:21:00.482Z","dependency_job_id":null,"html_url":"https://github.com/skrtdev/json2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skrtdev/json2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skrtdev%2Fjson2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skrtdev%2Fjson2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skrtdev%2Fjson2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skrtdev%2Fjson2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skrtdev","download_url":"https://codeload.github.com/skrtdev/json2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skrtdev%2Fjson2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271605082,"owners_count":24788842,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["class","hacktoberfest","json","mapper","php"],"created_at":"2024-12-20T10:29:04.340Z","updated_at":"2025-08-22T07:32:18.793Z","avatar_url":"https://github.com/skrtdev.png","language":"PHP","readme":"# JSON2\n\nJSON2 converts json and arrays in structured classes\n\nFull example\n```php\n\u003c?php\n\nuse skrtdev\\JSON2\\JSONProperty;\n\nrequire 'vendor/autoload.php';\n\nfunction api_call(...$args): string {\n    return file_get_contents('https://jsonplaceholder.typicode.com/'.implode('/', $args));\n}\n\n/** @var Post[] $posts */\n$posts = json2_decode(api_call('posts'), Post::class);\n\nclass Post{\n\n    #[JSONProperty(json: 'userId')]\n    protected int $user_id;\n    protected int $id;\n    protected string $title;\n    protected string $body;\n    \n    protected User $user;\n    \n    /**\n     * @var Comment[]\n     */\n    protected array $comments;\n    \n    /**\n     * @return User\n     * @throws ReflectionException\n     */\n    public function getUser(): User\n    {\n        return $this-\u003euser ??= json2_decode(api_call('users', $this-\u003euser_id), User::class);\n    }\n\n    /**\n     * @return Comment[]\n     */\n    public function getComments(): array\n    {\n        return $this-\u003ecomments ??= json2_decode(api_call('posts', $this-\u003eid, 'comments'), Comment::class);\n    }\n}\n\nclass User{\n    protected int $id;\n    protected string $name;\n    protected string $username;\n    protected Address $address;\n    protected Company $company;\n}\n\nclass Address{\n    protected Location $geo;\n}\n\nclass Location{\n    protected float $lat;\n    protected float $lng;\n}\n\nclass Company{\n    protected string $name;\n    #[JSONProperty(json: 'catchPhrase')]\n    protected string $catch_phrase;\n}\n\nclass Comment{\n    #[JSONProperty(json: 'postId')]\n    protected string $post_id;\n}\n\nvar_dump($posts);\n\nvar_dump($posts[30]-\u003egetUser());\nvar_dump($posts[6]-\u003egetComments());\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskrtdev%2Fjson2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskrtdev%2Fjson2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskrtdev%2Fjson2/lists"}