PHP Serialize
Runs in your browserPaste JSON and get the serialized string PHP’s serialize() would write for it, byte for byte.
JSON
Serialized PHP
253 B
How this one works
Paste JSON on the left and the serialized string appears on the right, exactly as PHP 8’s serialize(json_decode($json, true)) would write it. String lengths are counted in UTF-8 bytes, so "café" is s:5:, not s:4:.
Numbers keep their form: 2 becomes i:2; and 2.0 becomes d:2;, integers are copied digit for digit (past PHP’s 64-bit limit they become floats, as json_decode does), and keys like "5" become integer keys just as they do in PHP. An object with a "__class" key, like the ones PHP Unserialize produces, is written back as that PHP object, private and protected properties included.
It’s handy whenever you need a PHP serialized string without running PHP: a WordPress option or post meta value to write into the database, a fixture for a PHPUnit test, or a cached value to compare against.
Questions
Does the output match PHP exactly?
Yes. It follows PHP 8’s serialize() byte for byte, including UTF-8 string lengths and float formatting such as d:0.1; and d:1.0E+25;. The test suite compares it with the output of a real PHP 8.3 install.
Why does 2.0 become d:2; but 2 become i:2;?
Because that is what json_decode() does: a number written with a decimal point or an exponent is a float, and one without is an integer. This tool reads the number as written instead of letting JavaScript turn both into the same value.
How do I get a PHP object instead of an array?
Add a "__class" key with the class name. Properties named like "token (private)" or "role (protected)" are written with the NUL-byte names PHP uses for them, so the result unserializes into the real class.
Can I use the output in WordPress?
Yes. WordPress stores arrays in wp_options and post meta with PHP’s serialize(), so this is the same string those columns hold, and maybe_unserialize() reads it back. If you write it into the database directly, keep it exactly as generated: editing the text afterwards without updating the s:N lengths is what breaks serialized data.
Is my data sent anywhere?
No. The conversion is JavaScript running in this tab. Nothing you paste is uploaded or stored.