PHP serialization represents a value as a type-tagged string that PHP can reconstruct. Use this tool to convert JSON-compatible data into PHP's serialized syntax, inspect byte lengths, or reverse a supported serialized value while debugging an integration.
Serialization is not encryption and is usually a poor interchange format for new cross-language APIs. Prefer JSON when you control both sides and do not need compatibility with an existing PHP payload, cache entry, or stored value.
How to Use the PHP Serializer
Convert a JSON value and, when needed, switch direction to inspect the supported PHP representation.
- Keep Serialize selected in the Direction control.
- Enter an object, array, string, number, boolean, or
nullin JSON value. - Read the generated value in Serialized PHP string and check its byte count below the fields.
- Select Copy to copy the serialized output.
- Select Unserialize to change the input label to Serialized PHP string and the output label to JSON.
- Select Swap after a successful conversion to move the output into the input and reverse the direction.
Understanding PHP's Serialized Type Markers
PHP's format records a value's type and payload. N; represents null, b:1; a true boolean, i:42; an integer, d:9.5; a floating-point number, and s:3:"cat"; a three-byte string. Arrays include their entry count and a serialized key followed by a serialized value for each entry.
a:2:{s:2:"id";i:42;s:6:"active";b:1;}
When serializing, this tool maps JSON arrays to PHP arrays with sequential integer keys. JSON objects also become PHP arrays, using integer keys for canonical integer-like property names within JavaScript's safe range and string keys otherwise. It does not create serialized PHP objects from JSON objects.
JSON values and PHP values do not have identical type systems. JSON has no class instances, references, resources, NAN, or infinities. Conversely, PHP arrays can combine integer and string keys, while JSON distinguishes arrays from objects. Treat a round trip as a compatibility aid, not proof that every PHP value can be preserved in JSON.
UTF-8 Byte Lengths, Numbers, and JSON Limits
Serialized PHP strings store a byte length, not a JavaScript character count. This tool calculates that length from UTF-8 bytes, so s:4:"Zoë"; is correct: the visible string has three Unicode characters, but ë occupies two UTF-8 bytes. Editing the text without updating its declared length makes the serialized value invalid.
JSON input is parsed with the browser's standard JSON parser. Property names and strings need double quotes, and comments, trailing commas, undefined, NAN, and Infinity are rejected. When parsing fails, the tool reports an Invalid JSON message and includes line and column information when the browser exposes a usable error position.
Safe whole numbers are emitted with PHP's i: marker. Fractional values and integers outside JavaScript's safe-integer range are emitted with d:. However, the JSON parser has already represented every JSON number as a JavaScript Number, so a large integer may lose precision before serialization. Quote large identifiers when exact decimal digits matter.
The byte status describes the serialized output as UTF-8. It is not the count of PHP values, the JSON source size, or a guarantee that a receiving application's storage and character-encoding assumptions match.
Reverse Conversion and Unsupported PHP Values
Unserialize mode recognizes nulls, booleans, integers, floats, strings, arrays, ordinary serialized objects, enum cases, and backward references within the subset implemented by the parser. Sequential PHP array keys starting at zero become JSON arrays; other PHP arrays become JSON objects.
Ordinary O: objects are represented as JSON objects with a __class property. Private and protected property prefixes are removed from their serialized names. This makes output easier to inspect, but it is lossy: visibility metadata is not preserved, classes are not instantiated, and methods are not available.
Custom-serialized C: objects are rejected because interpreting them depends on the PHP class's own implementation. Backward references can be read, but JSON has no reference identity, so shared values may appear as ordinary duplicated structure in output. Self-referential graphs that depend on a container referring to itself are outside the supported conversion.
PHP NAN, INF, and -INF have no JSON numeric form. The tool warns about that mismatch and the JSON output shows them as null. PHP integers are read into JavaScript numbers in reverse mode, so very large integer values can also lose precision.
Security, Privacy, and Production Boundaries
PHP's native unserialize() can instantiate objects and invoke class-related behavior. PHP's manual warns against passing untrusted input to it, even when class restrictions are used. Authentication, such as a keyed message authentication code, must be verified before a production system treats a serialized payload as trusted.
This browser tool does not execute PHP, instantiate PHP classes, or invoke their magic methods. Its parser turns supported structures into JSON-compatible JavaScript data and rejects custom C: objects. That reduces a specific execution risk during inspection, but the resulting strings and values are still untrusted input and require validation before use elsewhere.
Conversion runs locally in the browser, and the tool does not upload the entered payload. Clipboard managers, screenshots, browser extensions, and anything you paste the result into remain separate exposure paths. Redact session data, personal information, and application secrets before sharing a serialized value.
For new APIs, use a documented format with an explicit schema rather than coupling another service to PHP's runtime-specific serialization. The JSON formatter can validate ordinary JSON, while the PHP to JSON converter handles PHP array literals and var_export()-style input rather than serialize() strings.
Frequently Asked Questions
Why is the length before a PHP string different from its character count?
PHP serialization records the string's byte length. This tool measures UTF-8 bytes, so non-ASCII characters can require more than one byte each. Changing a serialized string by hand requires recalculating the byte count.
Are JSON objects serialized as PHP objects?
No. JSON objects are serialized as PHP arrays with keyed entries, while JSON arrays use sequential integer keys. Serialize mode does not offer a class name or create the O: object form.
Can I safely pass untrusted output to PHP unserialize()?
No. PHP explicitly warns not to pass untrusted user input to unserialize() because object instantiation can create security risks. This tool's local inspection does not make a payload safe for a PHP application; authenticate and validate it according to the receiving system's threat model.
Why did a large integer change?
JSON numbers are parsed as JavaScript Number values before serialization, and integers beyond the safe range can lose precision at that stage. Reverse conversion also reads PHP integers into JavaScript numbers. Preserve exact large identifiers as strings when the surrounding format allows it.
Does Swap guarantee a lossless round trip?
No. Swap moves the current output into the input and reverses the direction, but the two data models differ. PHP objects, visibility prefixes, references, non-finite floats, mixed array keys, and large integers can lose information or change representation.
References: PHP Manual: serialize() · PHP Manual: unserialize().