Saltar al contenido
NewKitApp

Buscar herramientas

Salta a cualquier herramienta por su nombre

PHP Serialize / JSON Converter

Convert between PHP serialize() format and JSON — both directions, instantly in your browser.

PHP serialize

What is PHP Serialize / JSON Converter?

PHP's serialize() turns any PHP value into a compact, lossless text string so it can be stored in a database column, pushed through a cache like Redis or Memcached, or written into a session file. The format is terse — a leading type letter, a length, the value, terminated by a semicolon — for example `a:2:{s:1:"a";i:1;s:1:"b";s:2:"hi";}`. PHP arrays are unusual: a single array type doubles as both a list and a map, and serialize preserves integer/string keys exactly, so converting to JSON requires deciding per-array whether to emit a JSON array (sequential integer keys 0..n-1) or a JSON object. This tool does both conversions in either direction — JSON to PHP serialize, and PHP serialize to pretty JSON — entirely in your browser, with byte-accurate string length handling for multi-byte (UTF-8) content.

How to Use PHP Serialize / JSON Converter

  1. Pick a direction with the toggle at the top: "JSON → PHP" converts JSON into PHP serialize format, "PHP → JSON" does the reverse.
  2. Paste your JSON or PHP serialize string into the input box on the left.
  3. The converted result appears instantly in the output box on the right — no submit button.
  4. Use "Use output as input" to swap the result back into the input and flip the direction, which is handy for round-trip checks.
  5. Click "Copy output" to copy the result to your clipboard.

Examples

JSON object → PHP serialize

Input: {"name":"Alice","age":30,"active":true}

Output: a:3:{s:4:"name";s:5:"Alice";s:3:"age";i:30;s:6:"active";b:1;}

PHP sequential array → JSON array

Input: a:2:{i:0;s:5:"apple";i:1;s:6:"banana";}

Output: [ "apple", "banana" ]

PHP object (O:) → JSON object

Input: O:4:"User":2:{s:4:"name";s:5:"Alice";s:3:"age";i:30;}

Output: { "name": "Alice", "age": 30 }

Common Mistakes

  • Assuming PHP serialize is interchangeable with JSON — it is not. serialize preserves PHP-specific details like integer-vs-string keys, exact float formatting, and class membership, none of which JSON can represent directly.
  • Confusing byte length and character length in the s:<len>:"…"; marker. The length is the UTF-8 byte count, so an emoji like 🎉 is length 4, not 1.
  • Expecting private/protected object properties (serialized with null-byte-prefixed key names) to appear as clean JSON keys — they round-trip but their names contain control bytes that JSON escapes as \u0000.
  • Treating a non-sequential PHP array (e.g. keys 1, 0 or string keys) as a JSON array — this tool correctly emits a JSON object for those, matching PHP semantics.
  • Assuming the conversion is symmetric across object types: decoding O: yields a plain JSON object, but re-encoding that JSON produces an a: array, not the original PHP object.

Why Use This Tool

  • Two-way conversion in one tool — JSON to PHP serialize and PHP serialize to JSON, with a single direction toggle.
  • Byte-accurate string handling via TextEncoder/TextDecoder, so multi-byte and emoji content survives a round trip.
  • Smart array-vs-object detection that matches PHP's own list/map duality.
  • Runs entirely client-side — fast, private, and no upload limits beyond your browser's memory.
  • Clear, positioned error messages when input is truncated or malformed, so you can find and fix the problem quickly.

Frequently Asked Questions