Serialize / unserialize

Convert between JSON and PHP serialized data.

Paste data up to 1,000,000 UTF-8 bytes. Data stays in this browser and is not saved.

Inspect types and keys after conversion. This supports a restricted data subset and never executes PHP; it is not a lossless converter for every PHP value.

How it works

PHP uses type markers and UTF-8 byte lengths.

Worked examples

Typical task

Serialize the JSON string "café" to get s:5:"café";. Its four visible letters occupy five UTF-8 bytes because é takes two bytes.

A different case

An empty PHP array a:0:{} becomes JSON []. PHP arrays with consecutive integer keys from zero become arrays; nonconsecutive keys become JSON objects.

Instructions, limits, and common questions

Instructions

  1. Choose Serialize for JSON to PHP, or Unserialize for PHP to JSON.
  2. Paste your input or load the example, then select Convert.
  3. Copy the output. Editing the input clears the previous result.

Limits and assumptions

Supports null, booleans, finite numbers, UTF-8 strings, and arrays. PHP arrays with consecutive integer keys starting at 0 become JSON arrays; other arrays become JSON objects. An empty PHP array becomes []. Numeric JSON object keys become PHP integer keys where representable, so object/array identity and original numeric types may change on round trips. PHP objects, custom serialization, enums, references, binary strings, duplicate array keys, non-finite numbers, and unsafe integers are rejected. JSON numbers use JavaScript precision, so decimal precision beyond that range is not preserved. Limits: 1,000,000 input bytes and 100 nesting levels. This tool parses data and never executes PHP.

Why is the string length not its character count?

PHP serialized string lengths count bytes. This tool uses UTF-8, so accented characters can take multiple bytes.

Can I unserialize a PHP object?

No. Objects, references, enums, and custom serialization are rejected rather than instantiated or executed.

Are all numeric round trips exact?

No. Unsafe integers and non-finite numbers are rejected; JSON decimals use JavaScript precision and original numeric types can change.

References

Continue with a related task