Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions components/seo/UnserializerSEO.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export default function UnserializerSEO() {
return (
<div className="content-wrapper">
<section>
<h2>Free Online Unserializer - Parse Serialized Data Instantly</h2>
<p>
Paste a serialized string and instantly convert it into a
human-readable format. Choose between print_r() for a quick overview
or var_dump() for type-annotated detail. Ideal for inspecting
WordPress options, transients, and metadata stored in the database.
</p>
</section>

<section>
<h2>How to Use the Unserializer</h2>
<ul>
<li>
<b>Step 1:</b> <br />
Paste a serialized string into the input box. You can grab these
from database fields, API responses, or debug logs.
</li>
<li>
<b>Step 2:</b> <br />
Select an output format — <kbd>print_r()</kbd> for a compact view or{" "}
<kbd>var_dump()</kbd> for detailed type and length information.
</li>
<li>
<b>Step 3:</b> <br />
Copy the formatted output and use it in your debugging workflow.
</li>
</ul>
</section>

<section>
<h2>FAQs</h2>
<ul>
<li>
<b>What is a serialized string?</b>
<br />
Serialization converts a data structure into a compact string
representation for storage or transfer. This tool reverses that
process so you can read the original data.
</li>
<li>
<b>Where do I find serialized data?</b>
<br />
Common sources include the WordPress wp_options table, user meta
fields, WooCommerce order meta, transient caches, and plugin
settings stored in the database.
</li>
<li>
<b>What is the difference between print_r() and var_dump()?</b>
<br />
print_r() shows values and structure in a concise format. var_dump()
adds explicit type and length annotations for every value, which is
more useful for type-sensitive debugging.
</li>
<li>
<b>Does this tool modify the original data?</b>
<br />
No. The tool only reads and formats the input — nothing is stored,
sent, or altered.
</li>
</ul>
</section>
</div>
);
}
6 changes: 6 additions & 0 deletions components/utils/tools-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export const tools = [
"Format and beautify your JSON data for better readability and debugging. Quickly visualize and organize your JSON data with ease.",
link: "/utilities/json-formatter",
},
{
title: "Unserializer",
description:
"Parse serialized strings and render readable output in print_r() or var_dump() format. Useful for debugging WordPress database values.",
link: "/utilities/unserializer",
},
{
title: "JSONL Validator",
description:
Expand Down
148 changes: 148 additions & 0 deletions components/utils/unserializer.utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {
formatPrintR,
formatVarDump,
isValidSerialized,
unserialize,
} from "./unserializer.utils";

describe("unserializer.utils", () => {
describe("unserialize", () => {
test("parses primitive values", () => {
expect(unserialize('s:5:"hello";')).toEqual({
type: "string",
value: "hello",
});
expect(unserialize("i:42;")).toEqual({ type: "int", value: 42 });
expect(unserialize("d:3.14;")).toEqual({ type: "float", value: 3.14 });
expect(unserialize("b:1;")).toEqual({ type: "bool", value: true });
expect(unserialize("b:0;")).toEqual({ type: "bool", value: false });
expect(unserialize("N;")).toEqual({ type: "null" });
});

test("parses multi-byte UTF-8 strings", () => {
expect(unserialize('s:4:"😊";')).toEqual({
type: "string",
value: "😊",
});
});

test("parses nested arrays from sample payload", () => {
const input =
'a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}';

expect(unserialize(input)).toEqual({
type: "array",
entries: [
{
key: { type: "int", value: 0 },
value: { type: "string", value: "Sample array" },
},
{
key: { type: "int", value: 1 },
value: {
type: "array",
entries: [
{
key: { type: "int", value: 0 },
value: { type: "string", value: "Apple" },
},
{
key: { type: "int", value: 1 },
value: { type: "string", value: "Orange" },
},
],
},
},
],
});
});

test("resolves references", () => {
const result = unserialize('a:2:{s:1:"x";s:3:"foo";s:1:"y";R:2;}');
expect(result).toEqual({
type: "array",
entries: [
{
key: { type: "string", value: "x" },
value: { type: "string", value: "foo" },
},
{
key: { type: "string", value: "y" },
value: { type: "string", value: "foo" },
},
],
});
});

test("throws clear errors for invalid input", () => {
expect(() => unserialize("")).toThrow(
"Please enter a serialized string."
);
expect(() => unserialize("xyz")).toThrow();
expect(() => unserialize('a:1:{s:1:"x";R:99;}')).toThrow(
"Reference index 99 does not exist"
);
});
});

describe("isValidSerialized", () => {
test("returns true for valid payloads and false for invalid payloads", () => {
expect(isValidSerialized('s:5:"hello";')).toBe(true);
expect(isValidSerialized("i:42;")).toBe(true);
expect(isValidSerialized("")).toBe(false);
expect(isValidSerialized("not serialized")).toBe(false);
});
});

describe("formatPrintR", () => {
test("matches expected output for sample payload", () => {
const input =
'a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}';
const parsed = unserialize(input);

const expected = [
"Array",
"(",
" [0] => Sample array",
" [1] => Array",
" (",
" [0] => Apple",
" [1] => Orange",
" )",
"",
")",
].join("\n");

expect(formatPrintR(parsed)).toBe(expected);
});
});

describe("formatVarDump", () => {
test("matches expected output for sample payload", () => {
const input =
'a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}';
const parsed = unserialize(input);

const expected = [
"array(2) {",
" [0]=>",
' string(12) "Sample array"',
" [1]=>",
" array(2) {",
" [0]=>",
' string(5) "Apple"',
" [1]=>",
' string(6) "Orange"',
" }",
"}",
].join("\n");

expect(formatVarDump(parsed)).toBe(expected);
});

test("uses UTF-8 byte length for strings", () => {
const parsed = unserialize('s:4:"😊";');
expect(formatVarDump(parsed)).toBe('string(4) "😊"');
});
});
});
Loading