deserialize
Rebuilds the value serialize wrote, with its shared references and cycles.
Rebuilds the value serialize wrote, with its shared references and cycles. Plain objects
come back with a null prototype (so a __proto__ key is ordinary data), and malformed input throws
instead of producing a partial value. No code is evaluated.
Import#
ts
import { deserialize } from "@shadow-js/web/server";
Signature#
ts
function deserialize(text: string): unknown
Parameters#
| Name | Description |
|---|---|
text |
JSON text produced by serialize. |
Returns#
The rebuilt value.
Throws#
- SyntaxError when
textis not JSON; TypeError when the JSON is not in the formatserializewrites.
Examples#
ts
import { deserialize, serialize } from "@shadow-js/web/server";
const copy = deserialize(serialize({ tags: new Set(["a"]), total: 10n })) as {
tags: Set<string>;
total: bigint;
};
copy.tags.has("a"); // true