Serialize what JSON can't.
seroval turns JavaScript values into a string and back, including cyclic references, Date, Map, Set, BigInt and Promise, as code or as JSON.
npm install serovalpnpm add serovalyarn add serovalbun add serovalconst user = { name: "Ada", born: new Date("1815-12-10"), notes: new Map([["G", "Bernoulli"]]), }; user.self = user;
(h=>(h={name:"Ada",born:new Date("1815-12-10T00:00:00.000Z"),notes:new Map([["G","Bernoulli"]])},h.self=h,h))()back.born instanceof Dateback.notes.get("G") === "Bernoulli"back.self === back
JSON.stringify drops data. serialize keeps it.
Each row runs in your browser: JSON.stringify in the middle column, serialize in the right one.
Stream values as they resolve.
The synchronous part ships first and each promise follows when it settles, shown with real crossSerializeStream chunks.
Four output formats, same references.
Pick the format that fits the wire. Each one keeps shared and cyclic references.
One expression. Smallest output, needs eval.
- Size
- Needs eval
- Round trip
More types, built in or by plugin.
Core handles the JavaScript built-ins, and seroval-plugins adds the Web API types.
Built in
With seroval-plugins
Used by
- SolidJS
- TanStack Start
Questions
Is it safe to decode data from a client?
Yes, with the JSON functions. fromJSON validates the tree and runs no code from it. Never pass untrusted input to deserialize, which runs it. Security
Can the sender and receiver run different seroval versions?
Use the same version on both sides. The payload format can change in a minor release. SRV002
Where does it run?
Node.js 20 or later, Deno, Bun, browsers and edge runtimes. It has no dependencies. Compatibility
Can it send my own classes, or URL and Request?
Write a plugin for your classes. seroval-plugins covers URL, Headers, FormData, Request, Response, Blob, ReadableStream and more. Using plugins
Can it send functions?
Not their code. Register a function on both sides with createReference, and seroval sends its key. Isomorphic references
What does it cost?
Nothing. seroval is MIT licensed.
Send more than JSON.
npm install serovalpnpm add serovalyarn add serovalbun add seroval