thevenrex / json-to-class
Json Class initializer
v1.0
2024-09-30 22:18 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpunit/phpunit: ^11.3
README
Json Decoder into class
First step
use Thevenrex\JsonToClass\JsonToClassDecoder;
Usage
Create Class with public methods to used in json same
class User { public int $id; public string $name; public string $username; }
Create a new instance of JSON class with json raw
$json = '{ "id": 1, "name": "John Doe", "username": "johndoe" }'; $decoder = new JsonToClassDecoder($rawJson);
Decode content
$user = new User(); $decoder->decode($user);
The attributes is changed with json Datas
var_dump($user);
example output:
class User#3 (3) {
public int $id =>
int(1)
public string $name =>
string(5) "John Doe"
public string $username =>
string(10) "johndoe"
}