Download the PHP package zumba/json-serializer without Composer
On this page you can find all versions of the php package zumba/json-serializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zumba/json-serializer
More information about zumba/json-serializer
Files in zumba/json-serializer
Package json-serializer
Short Description Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.
License MIT
Homepage https://tech.zumba.com
Informations about the package json-serializer
Json Serializer for PHP
This is a library to serialize PHP variables in JSON format. It is similar of the serialize()
function in PHP,
but the output is a string JSON encoded. You can also unserialize the JSON generated by this tool and have you
PHP content back.
Supported features:
- Encode/Decode of scalar, null, array
- Encode/Decode of objects
- Encode/Decode of binary data
- Support nested serialization
- Support not declared properties on the original class definition (ie, properties in
stdClass
) - Support object recursion
- Closures (via 3rd party library. See details below)
Unsupported serialization content:
- Resource (ie,
fopen()
response) - NAN, INF constants
Limitations:
- Binary data containing null bytes (\u0000) as array keys cannot be properly decoded because of a json extension bug:
This project should not be confused with JsonSerializable
interface added on PHP 5.4. This interface is used on
json_encode
to encode the objects. There is no unserialization with this interface, differently from this project.
Json Serializer requires PHP >= 7.0 and tested until PHP 8.2
Example
How to Install
If you are using composer, install the package zumba/json-serializer
.
Or add the zumba/json-serializer
directly in your composer.json
file.
If you are not using composer, you can just copy the files from src
folder in your project.
Serializing Binary Strings
Binary strings introduce two special identifiers in the final json: @utf8encoded
and @scalar
.
@utf8encoded
is an array of keys from the original data which have their value (or the keys themselves)
encoded from 8bit to UTF-8. This is how the serializer knows what to encode back from UTF-8 to 8bit when deserializing.
Example:
@scalar
is used only when the value to be encoded is not an array or an object but a binary string. Example:
Serializing Closure
For serializing PHP closures you can either use OpisClosure (preferred) or SuperClosure (the project is abandoned, so kept here for backward compatibility).
Closure serialization has some limitations. Please check the OpisClosure or SuperClosure project to check if it fits your needs.
To use the OpisClosure with JsonSerializer, just add it to the closure serializer list. Example:
You can load multiple closure serializers in case you are migrating from SuperClosure to OpisClosure for example.
PS: JsonSerializer does not have a hard dependency of OpisClosure or SuperClosure. If you want to use both projects
make sure you add both on your composer requirements and load them with addClosureSerializer()
method.
Custom Serializers
Some classes may not be suited to be serialized and unserialized using the default reflection methods.
Custom serializers provide the ability to define and methods for specific classes.
All versions of json-serializer with dependencies
ext-mbstring Version *