PHP code example of mindplay / jsonfreeze

1. Go to this page and download the library: Download mindplay/jsonfreeze library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mindplay / jsonfreeze example snippets


use mindplay\jsonfreeze\JsonSerializer;

$serializer = new JsonSerializer();

// serialize to JSON:

$string = $serializer->serialize($my_object);

// rebuild your object from JSON:

$object = $serializer->unserialize($string);

$serializer = new JsonSerializer();

$serializer->defineSerialization(
    MyType::class,
    function (MyType $object) {
        return ["foo" => $object->foo, "bar" => $object->bar];
    },
    function (array $data) {
        return new MyType($data["foo"], $data["bar"]);
    }
);