Serialize and Unserialize Data Converter Tool
Convert serialized data, array, object, JSON, XML, HTTP Query to unserialized data, serialized, JSON, XML, HTTP Query output data
Paste or upload serialized data, array, object, json, xml, http query to unserialized data
Serialize and Unserialize Data Converter: Turn Any Data Format Into Any Other Format, Instantly
Every PHP application eventually has to answer the same question: how do I take a value sitting in memory — an array, an object, a database row — and turn it into something I can store, cache, send over a network, or hand to another system? The Serialize and Unserialize Data Converter is built to answer that question without forcing you to open a code editor, spin up a local PHP environment, or write a single throwaway script just to inspect one value.
This guide walks through what serialized and unserialized data actually are, how PHP's native serialize() format compares to JSON, XML, arrays, objects, and HTTP query strings, and exactly how to move data between all of these formats using the free online converter at onlinewebtoolkit.com/unserialize.
Whether you're debugging a corrupted PHP session, reverse-engineering a third-party API response, migrating legacy serialized columns out of a MySQL database, or simply trying to understand what a:2:{s:4:"name";s:4:"John";} actually means, this converter — and the explanations below — are built to get you from confused to confident in a few minutes.
The tool accepts six distinct input formats and produces eight distinct output formats, which means there are dozens of practical conversion paths available from a single text box: serialized PHP to JSON, JSON to serialized PHP, XML to array, HTTP query string to object, and every other combination you're likely to need during day-to-day development, debugging, or data migration work.
What is Serialized Data?
Serialized data is the byte-by-byte text representation of a value — a string, number, array, or object — that has been flattened into a single linear string so it can be stored or transmitted, then rebuilt back into its original structure later. In PHP specifically, this is the job of the built-in serialize() function, and the format it produces is often just called "PHP serialized data" or "a serialized array."
The defining trait of PHP's serialization format, compared to JSON or XML, is that it is self-describing at the byte level. Every value is preceded by a single-letter type marker and, for strings, an explicit byte length. That's why a serialized string looks like s:4:"John"; instead of simply "John" — the s says "this is a string," the 4 says "exactly four bytes follow," and everything inside the quotes is the literal payload.
This length-prefixing is a deliberate design choice. It means the parser never has to guess where a string ends by scanning for an unescaped quote character — it just reads four bytes and stops, which makes the format fast to parse and resistant to certain string-escaping bugs that plague naive JSON or CSV parsers. The tradeoff is that serialized strings become fragile the moment a human edits them by hand, because changing the value without recalculating the length breaks the entire structure.
Anatomy of a serialized array
Take the associative array ['name' => 'John', 'age' => 30]. Running it through serialize() produces:
a:2:{s:4:"name";s:4:"John";s:3:"age";i:30;}
Reading it left to right: a:2: means "an array with 2 key-value pairs follows." Then each pair is written as key, then value, both wrapped in their own type:length:value triplets, with the whole array closed by a final curly brace.
Serialized objects look almost identical
Objects use the same pattern but start with O instead of a, and include the class name and property count:
O:4:"User":2:{s:4:"name";s:4:"John";s:3:"age";i:30;}
That extra "User" after the property count is the class name PHP needs to reconstruct the right object type when it unserializes the string back — which is also exactly why mixing serialized objects between codebases, or unserializing data from an untrusted source, deserves caution (more on that in the security section below).
In short: serialized data isn't a generic "compressed" or "encrypted" blob — it's a plain-text, fully readable encoding of a value's exact type and structure, designed specifically so PHP can rebuild that value perfectly later.
What is Unserialized Data?
Unserialized data is simply the original value — restored. It's what you get after running a serialized string back through PHP's unserialize() function: the flat, length-prefixed text turns back into a real, usable array, object, string, integer, boolean, or null that your application can loop over, read properties from, or pass into other functions exactly as if it had never left memory in the first place.
It helps to think of serialize and unserialize as a matched pair, the way zip and unzip are a matched pair. Serializing flattens a structure into a transportable string; unserializing inflates that string back into the original structure. If the round trip is done correctly, unserialize(serialize($value)) and $value are functionally identical.
Why "unserialized" isn't a single fixed format
This is the part that trips a lot of people up: once you've unserialized a value, you still need to decide how to look at it or output it, and PHP — and this converter — give you several different views of that same underlying value:
- print_r output — a clean, indented, human-readable tree. No type information, no quotes around strings beyond what you'd naturally expect. This is what most developers reach for first when debugging.
- var_dump output — the same structure, but annotated with explicit data types and string byte-lengths for every single value. This is the version to use when a bug might be caused by a type mismatch, like a numeric string
"30"being mistaken for an integer30. - var_export output — valid, runnable PHP source code that, if pasted directly into a script, recreates the exact same value. This is the version to use when you want to hard-code a fixture, a config default, or a test case.
The converter generates all three views from the same input, so instead of mentally translating between formats, you can simply pick whichever representation answers the question you're actually asking right now.
Quick distinction: "Unserialized" describes the state of the data (rebuilt, native, structured). print_r / var_dump / var_export are just three different ways of displaying that same unserialized state as text.
Key Features of the Serialize and Unserialize Data Converter
The converter is built around one idea: any structured value should be readable, and convertible, regardless of which format it currently happens to be in. To make that work in practice, it supports six input formats and eight output formats, giving you 48 possible conversion paths from a single paste-and-select interface. Below, every format is broken down with a short explanation and a worked example using the same sample record — id: 101, name: "John Doe", active: true — so you can see exactly how the same data looks across every representation.
Input Formats
Paste data in any of the six formats below, and the converter detects its structure and prepares it for conversion into whichever output format you choose.
Serialized
Paste an existing PHP serialized string and the converter parses every type marker and length prefix automatically.
a:3:{s:2:"id";i:101;s:4:"name";s:8:"John Doe";s:6:"active";b:1;}Array
Write a PHP array using normal array syntax — short [ ] brackets or array() both work.
[ 'id' => 101, 'name' => 'John Doe', 'active' => true]
Object
Paste a PHP object literal (stdClass or a typed class) and it's read property by property.
(object) [ 'id' => 101, 'name' => 'John Doe', 'active' => true]
JSON
Drop in any valid JSON document — objects, arrays, or a mix of both, nested as deep as you need.
{ "id": 101, "name": "John Doe", "active": true}HTTP Query
Paste a raw query string exactly as it appears after the ? in a URL, with keys joined by &.
id=101&name=John+Doe&active=1
XML
Paste a well-formed XML document and each element becomes a key in the resulting structure.
<root> <id>101</id> <name>John Doe</name> <active>1</active></root>
Output Formats
Once your input is parsed, select any of these eight output formats to generate the equivalent representation. Several output options exist specifically because different tasks call for different views of the same underlying value.
Unserialized print_r
A clean, indented tree with no type annotations — the fastest way to eyeball a structure's shape.
Array( [id] => 101 [name] => John Doe [active] => 1)
Unserialized var_dump
The same tree, annotated with explicit types and string lengths for precise type debugging.
array(3) { ["id"]=> int(101) ["name"]=> string(8) "John Doe" ["active"]=> bool(true)}Unserialized var_export
Valid, copy-pasteable PHP code that recreates the exact value when executed in a script.
array ( 'id' => 101, 'name' => 'John Doe', 'active' => true,)
Serialized
The compact, length-prefixed PHP format, ideal for storing values in a database column or cache.
a:3:{s:2:"id";i:101;s:4:"name";s:8:"John Doe";s:6:"active";b:1;}Object
Renders the value as a PHP object instance instead of an associative array, property by property.
(object) array( 'id' => 101, 'name' => 'John Doe', 'active' => true,)
JSON
A compact, language-independent JSON document, ready to send to any frontend, API, or non-PHP service.
{"id":101,"name":"John Doe","active":true}XML
A well-formed XML document with matching element names, suitable for legacy SOAP or XML-based systems.
<root><id>101</id><name>John Doe</name><active>1</active></root>
HTTP Query
A flat, URL-encoded query string, ready to append to a GET request or use as a form body.
id=101&name=John+Doe&active=1
Why so many formats?
In a real codebase, the same piece of data routinely passes through several of these formats in a single request lifecycle: a query string arrives over HTTP, gets parsed into an array, is serialized for storage in a session or cache, and may eventually be exposed to a frontend as JSON or to a partner system as XML. Having one tool that speaks all six input dialects and all eight output dialects removes the need to context-switch between a JSON formatter, a separate PHP sandbox, and a manual XML editor just to trace one value through that pipeline.
It also means you can use the converter as a translation layer between systems that were never designed to talk to each other directly — for example, taking a legacy serialized PHP column and producing the JSON payload a modern JavaScript frontend actually expects, without writing a migration script for a single one-off check.
How to Use the Serialize and Unserialize Data Converter Tool
Open onlinewebtoolkit.com/unserialize and you'll find a single input box, a format selector, and an output panel. There's no sign-up, no file upload, and nothing to install. Here's the full workflow from raw data to converted output:
Paste your data into the input field
Copy the value you want to convert — a serialized string pulled from a database column, a JSON response from an API, a query string copied out of a browser's address bar, an XML payload, or a plain PHP array or object you've written by hand — and paste it directly into the input box.
Select the input format
Tell the converter what you just pasted: Serialized, Array, Object, JSON, HTTP Query, or XML. This lets the parser apply the correct rules immediately rather than trying to guess the format from the raw text, which keeps the conversion accurate even when the data is ambiguous (for example, a string that happens to look numeric).
Choose the output format you need
Pick from Unserialized print_r, Unserialized var_dump, Unserialized var_export, Serialized, Object, JSON, XML, or HTTP Query. If you're not sure which one you need, print_r is the safest default for a quick read, var_dump is best when types matter, and JSON is best if the result is heading anywhere outside PHP.
Review, copy, and reuse the output
The converted value appears instantly in the output panel, formatted and ready to copy. Drop it straight into your code editor, a database query, an API request body, or a debugging note — there's no extra cleanup step required.
Try it on your own data
Paste a serialized string, an array, or a JSON payload and see every output format generated at once.
A worked example, start to finish
Say you've pulled this value out of a wp_options database column and need to know what's actually inside it:
a:2:{s:5:"theme";s:8:"midnight";s:7:"version";d:2.4;}
Set the input format to Serialized, paste the string above, set the output format to Unserialized print_r, and the converter returns:
Array( [theme] => midnight [version] => 2.4)
Switch the output format to JSON on the same input without retyping anything, and you instantly get {"theme":"midnight","version":2.4} — ready to hand off to a frontend or log into a monitoring tool.
Serialized and Unserialized Data: Uses and Applications
Serialization isn't a niche technique reserved for advanced PHP work — it's quietly running underneath some of the most common operations in web development. Understanding where it shows up makes it much easier to recognize a serialized string the moment you see one, instead of mistaking it for corrupted data or a bug.
Session storage
By default, PHP stores $_SESSION data on disk as a serialized string between requests. Every time a user logs in, adds an item to a cart, or moves through a multi-step form, PHP is serializing that session array behind the scenes and unserializing it back on the next request.
Caching layers
Tools like Memcached and Redis, when used through PHP's caching libraries, frequently store complex values — query results, computed objects, API responses — as serialized strings, because serialization is fast and preserves exact PHP types without the overhead of a full database round-trip.
Database columns
It's extremely common to find a single database column holding a serialized array instead of a normalized set of columns or a separate table — WordPress's wp_options table is a well-known example, where plugin settings, theme configuration, and widget data are all stored as serialized PHP arrays in a single option_value column.
REST API payloads
Modern APIs almost always exchange JSON, not PHP-serialized data — but the backend logic generating that JSON is frequently working with native PHP arrays and objects internally, which means converting between JSON and PHP structures (in both directions) happens constantly during API development and debugging.
Config and options storage
Application settings, feature flags, and user preferences are often stored as a single serialized blob rather than dozens of individual rows, because it keeps related settings grouped together and avoids constant schema changes every time a new setting is added.
Legacy data migration
When moving data out of an older PHP application — into a new framework, a different language entirely, or a modern JSON-based API — serialized columns need to be unserialized first and then re-encoded into a portable format like JSON or XML before they're usable anywhere else.
Serialize vs JSON: Which Format Should You Actually Use?
This is one of the most common questions developers run into once they realize PHP gives them two completely different ways to flatten a value into a string. The short answer: use JSON when data needs to leave PHP, and use serialize() when data is staying inside PHP. The longer answer depends on what you're optimizing for.
JSON is a language-independent standard. A JSON string produced by PHP can be parsed natively by JavaScript in the browser, by Python on a data pipeline, by a mobile app written in Swift or Kotlin, or by virtually any modern programming language without a special library. That universality is exactly why REST APIs settled on JSON as the default exchange format.
PHP's serialize() format, on the other hand, is PHP-specific by design. It can represent things JSON simply has no syntax for — like which class an object was instantiated from, or which properties were declared private versus public. That extra fidelity is valuable when data never leaves PHP, but becomes a liability the moment another language needs to read it, because that language has no native way to interpret O:4:"User":2:{...}.
| Property | PHP Serialize | JSON |
|---|---|---|
| Readable across languages | No — PHP-specific syntax | Yes — universal standard |
| Preserves object class names | Yes | No |
| Safe to edit by hand | Risky — length prefixes break easily | Generally safe |
| Native browser/JS support | No | Yes |
| Typical home | Sessions, caches, internal storage | APIs, configs, public data exchange |
| Parsing speed in PHP | Very fast (built-in, no extension) | Fast (built-in json_decode) |
In practice, most modern PHP applications use both, just for different jobs: serialize() for fast, type-preserving internal storage, and json_encode()/json_decode() for anything that touches an API, a frontend, or another service. The converter on this page makes switching between the two — in either direction — a copy-paste operation instead of a coding task.
Security Considerations When Working With Serialized Data
Serialization is safe in the overwhelming majority of everyday use — reading config values, debugging a session, converting between formats for a script you control. The risk shows up specifically when unserialize() is called on data that came from somewhere untrusted: a query parameter, a form field, a cookie, or any other input an attacker could potentially shape.
What is PHP Object Injection?
Because a serialized object string can specify any class name available in the application — O:9:"SomeClass":... — an attacker who controls the string passed into unserialize() can potentially instantiate classes that were never meant to be created from user input. If any of those classes define "magic methods" like __wakeup(), __destruct(), or __toString(), those methods run automatically the moment the object is built or destroyed — which is the foundation of a class of attacks known as PHP Object Injection (sometimes chained into full remote code execution depending on what those magic methods do).
This isn't a flaw in the serialization format itself — it's a consequence of trusting input that hasn't been validated. The same caution that applies to SQL injection or unsanitized file paths applies here: never feed external input directly into a function that can act on it without restriction.
How to stay safe
- Never unserialize raw user input. If a value needs to come from a request, prefer JSON (
json_decode()) for anything user-facing, since JSON has no concept of arbitrary class instantiation. - Use the
allowed_classesoption. Since PHP 7.0,unserialize()accepts a second argument that restricts which classes (if any) are allowed to be instantiated — passingfalseblocks all objects outright. - Sign or encrypt data you control but store externally, such as in a cookie, so a tampered string is rejected before it ever reaches
unserialize(). - Treat this converter, and any online tool, as a read-only inspection utility for understanding and reformatting data you already have — not as a substitute for proper input validation in production code.
Rule of thumb: if you didn't generate the serialized string yourself, or it could have passed through a place an attacker can reach, treat it as untrusted and avoid unserializing it in your application's runtime — inspect it with a converter or sandbox instead.
Benefits of Using the Serialize and Unserialize Data Converter
The case for using a dedicated converter over writing one-off scripts comes down to speed, accuracy, and flexibility. Here's what changes once this becomes part of your regular toolkit:
Saves debugging time
Stop manually tracing length prefixes by hand — see the full structure and value types in one read instead of reverse-engineering the format line by line.
No local environment needed
Convert and inspect data without spinning up PHP, installing an IDE, or writing a throwaway script just to check one value.
Bridges PHP and non-PHP systems
Move data between PHP-only serialized storage and universally-readable JSON or XML in seconds, without a custom migration script.
Reduces copy-paste errors
Hand-editing a serialized string almost always breaks its length prefixes — generating it through the converter avoids that entirely.
Multiple debug views from one input
Get print_r, var_dump, and var_export output from the same paste, instead of running three separate PHP commands.
Works for one-off checks and recurring tasks
Equally useful for a five-second sanity check on a database value or a repeated part of a data-migration workflow.
Type-safe conversions
Booleans, integers, floats, and nulls are preserved correctly across formats instead of silently turning into strings.
Free and accessible anywhere
No account, no installation, no cost — open the page from any device with a browser and get to work immediately.
Common Errors When Working With Serialized Data (And How to Fix Them)
Most problems with serialized data come down to one root cause: the length prefixes inside the string no longer match the actual content. Here are the errors you're most likely to run into, and what's usually causing each one.
"unserialize(): Error at offset X of Y bytes"
This is the single most common serialization error. It means the parser counted the declared length of a value and reached a point in the string that didn't match what it expected — usually a quote character, a semicolon, or a closing brace. The typical causes are:
- The string was edited by hand without recalculating the length prefix after the value changed.
- The data was truncated — often by a database column with a length limit smaller than the serialized string, or by output buffering cutting off a response early.
- The character encoding changed between when the string was serialized and when it's being unserialized, so byte counts no longer line up with character counts (this is especially common with multi-byte UTF-8 text).
- Magic quotes, escaping, or a find-and-replace operation altered quote characters or backslashes somewhere inside the string.
The fix: don't try to patch the broken string by hand. Regenerate it from the original source data using serialize() again, or — if you only have the broken string — paste it into the converter's Serialized input to see exactly where the structure breaks down.
"Notice: unserialize(): Unexpected end of serialized data"
This means the string is missing data at the end — typically the closing brace or a trailing value was cut off, often by a database field that silently truncated a value exceeding its maximum length.
A serialized string round-trips into the wrong type
If a value comes back as a string when it was originally an integer (or vice versa), the issue is almost always upstream — a value was cast to a string before being serialized, often by something as simple as concatenating it into another string first. Check the original source rather than the serialized output.
JSON to serialize conversion loses object class information
This is expected behavior, not a bug. JSON has no concept of PHP class names, so converting JSON into serialized data will always produce an array or a generic stdClass object rather than an instance of a specific custom class — the class name simply isn't present anywhere in the JSON to recover.
XML conversion drops attributes or repeated tags
XML supports patterns that don't map cleanly onto arrays or JSON — element attributes, mixed content, and multiple sibling elements with the same tag name. When converting from XML, check the output carefully against the source for any of these patterns, since they sometimes need to be restructured slightly to convert losslessly.
Glossary: Key Terms Used Throughout This Guide
A quick reference for the vocabulary that comes up repeatedly when discussing serialized and unserialized data, useful if you've landed on this page from a search for one specific term.
| Term | Meaning |
|---|---|
| Serialize | The process of converting a structured value (array, object, string, number) into a single flat string that can be stored or transmitted, using PHP's serialize() function. |
| Unserialize | The reverse process — converting a serialized string back into its original PHP value, using the unserialize() function. |
| Type marker | The single letter at the start of each serialized value (s, i, d, b, a, O, N) that tells the parser whether the value is a string, integer, double, boolean, array, object, or null. |
| Length prefix | The number immediately following a string's type marker, indicating the exact byte length of the value that follows — this is what allows the parser to read a string without scanning for a closing quote. |
| print_r | A PHP function that outputs a human-readable, indented representation of a value with no type annotations, commonly used for quick debugging. |
| var_dump | A PHP function that outputs a value's structure along with explicit data types and string lengths for every element — more verbose than print_r but more precise. |
| var_export | A PHP function that outputs valid, executable PHP code representing a value, suitable for pasting directly into a script. |
| stdClass | PHP's generic, built-in object type, used whenever a value is cast to an object without belonging to a specific custom class. |
| HTTP query string | The portion of a URL after the ? character, made up of key-value pairs joined by &, such as id=101&active=1. |
| JSON-LD | A JSON-based format for structured data, unrelated to PHP serialization but worth distinguishing from it since both involve the word "serialize" in different contexts (structured data markup vs. PHP's native data format). |
Frequently Asked Questions
Answers to the questions that come up most often when working with serialized data, JSON, XML, arrays, objects, and HTTP query strings.
PHP serialize() produces a PHP-specific string with explicit type markers and byte lengths, capable of representing PHP objects, class names, and private or protected properties. JSON is language-independent and only represents plain data — objects, arrays, strings, numbers, booleans, and null — without any PHP-specific type information. JSON works in any language; serialized PHP data is reliably read only by PHP.
Yes. Paste your JSON into the input box, set the input format to JSON and the output format to Serialized, and the converter generates the equivalent PHP serialized string, preserving nested arrays and objects correctly.
Avoid pasting passwords, API keys, access tokens, or personal data into any online converter. For sensitive production data, prefer running serialize() and unserialize() locally in a trusted, offline environment rather than a web-based tool.
It means the byte-length prefix inside the serialized string doesn't match the actual length of the value that follows — usually because the string was hand-edited, truncated by a database column limit, or had its character encoding changed. Regenerate the string with serialize() from the original source rather than editing the broken string directly.
Yes. XML can be selected as an input format and converted into JSON, serialized PHP data, an array, an object, or an HTTP query string. The reverse conversion, from JSON into XML, is also supported.
print_r produces a simple, indented, human-readable tree without showing data types. var_dump shows the same structure with explicit types and string lengths attached to every value, which helps catch type mismatches. var_export produces valid, runnable PHP code that recreates the exact value when executed in a script.
Select HTTP Query as the input format, paste a string such as id=101&name=John+Doe&active=1, choose JSON as the output format, and each key-value pair is parsed into a matching JSON object property.
Not natively. Serialized PHP strings use PHP-specific type markers that are only parsed correctly by PHP's unserialize() function or a library specifically written to read that exact format. For cross-language data exchange, JSON or XML are the appropriate choice.
PHP Object Injection is a vulnerability that arises when untrusted, user-supplied data is passed directly into unserialize(), allowing an attacker to construct objects that trigger unintended behavior through magic methods such as __wakeup() or __destruct(). The standard mitigation is to never unserialize untrusted input, or to restrict allowed classes using the allowed_classes option introduced in PHP 7.
Yes. Enter the array using standard PHP array syntax, set the input format to Array and the output format to Serialized, and the converter generates the matching serialized string without requiring a local PHP environment.
var_dump is best for debugging because it exposes exact data types, string lengths, and nesting. Serialized format is best for storage in databases, caches, or session files because it's compact and round-trips cleanly. JSON is usually the right choice for storage or transfer when the data needs to be readable outside of PHP.
The tool is designed for typical development and debugging payloads — individual values, config blocks, API responses, and database column contents. Extremely large datasets, such as entire database exports, are better handled with a local script rather than pasted into a browser-based tool.
Ready to convert your data?
Serialized, array, object, JSON, XML, or HTTP query in — print_r, var_dump, var_export, serialized, object, JSON, XML, or query out.

