JSON Serialize to PHP
ED-59Paste JSON to get the string PHP serialize() would write for the same data, or paste a PHP serialized string to see it as JSON.
Runs in your browser. Nothing is uploaded.
JSON (or a PHP serialized string)
Result
How to use it
- Paste your JSON into the input box.
- Click JSON to PHP serialize to get the serialized string.
- To go the other way, paste a string such as a:2:{i:0;s:1:"a";i:1;s:1:"b";} and click PHP serialize to JSON.
- Choose the JSON indent for the unserialized result, then copy it or download it.
The PHP serialize format
PHP stores a value as text: s:3:"Ada"; for a string (the number is the length in UTF-8 bytes), i:42; for an integer, d:19.5; for a decimal, b:1; for a boolean, N; for null, and a:2:{...} for an array with two entries. JSON objects and arrays both become PHP arrays. A JSON array uses keys 0, 1, 2, and an object uses its own keys. Whole-number keys such as "5" become integer keys, as PHP does.
Where it can differ
An empty object and an empty array both serialize to a:0:{}, and read back as an empty array. An integer outside the 64-bit range is an error instead of being rounded into a float, so no digits are lost. Decimals are written the way JavaScript prints them, which PHP can read, but the text may differ from what PHP itself would write for exotic values.
Reading serialized data
Reading supports null, booleans, integers, doubles, strings, arrays and objects. An object becomes a JSON object with a __class key holding the class name, and private and protected property prefixes are removed. References (r: and R:) and the C: and E: types are not supported, and INF and NAN are rejected because JSON cannot hold them. Strings are checked against their stated byte length.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Input is not valid JSON | The text on the left is not parseable JSON; the message adds the line and column. | Fix the JSON at that position. |
does not fit in a 64-bit integer | A whole number is larger than PHP can hold as an integer. | Write the value as a string instead. |
Extra data after the end of the value | The serialized string continues after a complete value. | Remove the trailing characters or paste one value at a time. |
Questions people ask
How do I convert JSON to PHP serialized data?
Paste the JSON and click JSON to PHP serialize. Objects and arrays become PHP arrays, strings get their byte length, and numbers, booleans and null get the matching i:, d:, b: and N; forms.
How do I unserialize a PHP string online?
Paste the serialized string and click PHP serialize to JSON. The tool reads it type by type, checks string lengths and shows the data as indented JSON. Nothing is run, so object classes are only labelled with a __class key.
Why are string lengths in bytes?
PHP counts the length of s: values in bytes, not characters. A string with é has length 2 for that letter and an emoji has 4. The tool counts UTF-8 bytes, so the output matches what PHP expects.
What happens to nested objects?
Nested JSON objects and arrays become nested a: arrays. The output keeps the order of keys. If a key appears twice in a JSON object, the last value wins and the entry keeps its first position, which matches how PHP arrays behave.
Which serialized types can be read?
Null, booleans, integers, doubles, strings, arrays and objects. References, Serializable objects (C:) and enums (E:) are rejected with a clear message. Doubles that are INF or NAN are rejected too, because JSON has no way to write them.
Is serialized PHP the same as JSON?
No. They both store structured data as text, but the formats differ and are not interchangeable. PHP serialize records types and byte lengths and can include class names, while JSON is a simpler, language-neutral format.
About this tool
This writes the text format used by PHP serialize(): s:3:"Ada"; for strings (the number is the length in UTF-8 bytes), i: for integers, d: for decimals, b: for booleans, N; for null and a: for arrays. JSON arrays and objects both become PHP arrays; an empty object and an empty array give the same output, and keys that are whole numbers become integer keys. An integer that does not fit in 64 bits is an error rather than a rounded float. Reading goes the other way for null, booleans, integers, doubles, strings, arrays and O: objects (written with a __class key). References (r:, R:) and other types such as C: and E: are not supported, and INF and NAN cannot be written in JSON.