Rewrite serialization to json_encode and _decode