Superjson extends JSON.stringify and parse to round-trip JavaScript values such as Date, Map, Set, and BigInt safely in TypeScript and JavaScript projects.
Overview
Superjson addresses gaps where plain JSON drops type information for rich JavaScript values. It wraps serialization with metadata so parsers can reconstruct Dates, collections, and other supported types on the other side.
The API mirrors familiar JSON.stringify and JSON.parse calls, with optional in-place mutation for performance on large objects. Advanced serialize and deserialize functions expose separate json and meta payloads for APIs that must stay JSON-compatible on the wire.
Framework-agnostic usage fits Next.js getServerSideProps and similar environments that otherwise stringify dates manually. TypeScript typings ship with the package for autocomplete and type safety.
Key features
- Date and BigInt serialization
- Map and Set support
- TypeScript typings
- Framework agnostic
- Next.js-friendly helpers
- Separate meta payloads
- In-place mutation option
- Small runtime footprint
Use cases
- Next.js server props transport
- APIs with rich JS types
- Caching structured app state
- Isomorphic client-server data