Skip to content

PHP Serialize

Runs in your browser

Paste 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.

Keyboard shortcuts

Global

  • Show this shortcuts dialogShift?
  • Toggle light / dark themeCtrlShiftL
  • Close dialogsEsc

Formatter & Validator

  • Format JSONCtrlEnter
  • Minify JSONCtrlShiftM
  • Copy outputCtrlShiftC
  • Download output as .jsonCtrlShiftS
  • Clear input and outputCtrlShiftX

Tree Viewer

  • Focus the search box/
  • Expand all nodesCtrlShiftE
  • Collapse all nodesCtrlShiftR

Diff

  • Swap document A and BCtrlShiftS

Time & date tools

  • Use the current time (Epoch Converter)CtrlEnter
  • Copy the main resultCtrlShiftC
  • Clear the inputCtrlShiftX

PHP Unserialize & Serialize

  • Convert an input over 2 MBCtrlEnter
  • Copy outputCtrlShiftC
  • Download outputCtrlShiftS
  • Clear input and outputCtrlShiftX

Keys & IDs

  • Generate a new token or UUID batchCtrlEnter
  • Copy the resultCtrlShiftC

JSON tools

JSON FormatterPretty-print or minify
JSON ValidatorCheck strict JSON validity
JSON Tree ViewerBrowse JSON as a tree
JSON DiffCompare two documents
JSON Path FinderExplore JSONPath expressions
JSON → CSVFlatten JSON into rows
CSV → JSONTurn rows back into objects
PHP UnserializeSerialized PHP to JSON
PHP SerializeJSON to serialized PHP

JWT tools

JWT DecoderRead header, payload, claims
JWT VerifierCheck an HMAC signature
JWT Expiry Checkeriat, nbf and exp in local time
JWT GeneratorBuild a signed test token
Base64URL EncoderEncode or decode a segment

Time & date tools

Epoch ConverterTimestamps to real dates
Cron Expression ExplainerCron in plain English
Time Zone ConverterOne moment, many cities
Duration CalculatorDate maths and durations

Keys & IDs

Password GeneratorSecure random secrets
UUID Generatorv1, v4, v5 or v7 UUIDs

Code formatters

SQL FormatterBeautify or minify SQL
HTML FormatterBeautify or minify HTML
CSS FormatterBeautify or minify CSS
JavaScript FormatterBeautify or minify JS
PHP FormatterBeautify PHP code
Markdown to HTMLConvert with a live preview

Pages

JSON toolsFormat, validate, compare and convert JSON.
JWT toolsDecode, verify and generate JSON Web Tokens.
Time & date toolsConvert timestamps, read cron, compare zones.
Keys & IDsGenerate secure tokens, passwords and UUIDs.
Code formattersFormat SQL, HTML, CSS, JavaScript and PHP code.
HomePopular tools and categories
All categoriesBrowse tools by category
AboutWhat ToolJar is and why
PrivacyWhat is and is not collected

Theme

Switch to light theme
Switch to dark theme