superjson
JSON superset that serializes JavaScript's full type system — safely transport Dates, Maps, Sets, BigInts, and undefined over the wire.
superjson
General JSJSON superset that serializes JavaScript's full type system — safely transport Dates, Maps, Sets, BigInts, and undefined over the wire.
Fit
Bundle (gzip)
3.9 kB
10.8 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
JSON.stringify loses Date objects (converts to strings), drops undefined values, and can't handle Map, Set, RegExp, or BigInt. Deserializing API responses requires manual date reconstruction throughout your codebase.
What It Does
SuperJSON serializes any JavaScript value to a JSON-compatible format that includes type metadata. superjson.parse() reconstructs the original types exactly — a Date comes back as a Date, a Map as a Map. Used by tRPC and Blitz.js as the default serialization layer.
Installation
npm install superjsonUsage Example
import superjson from 'superjson';
const data = {
createdAt: new Date('2025-01-15'),
tags: new Set(['react', 'typescript']),
meta: new Map([['version', 2]]),
count: BigInt(9007199254740993),
};
const json = superjson.stringify(data);
// '{"json":{"createdAt":"2025-01-15T00:00:00.000Z",...},"meta":{"values":{"createdAt":["Date"],...}}}'
const restored = superjson.parse<typeof data>(json);
restored.createdAt instanceof Date; // true
restored.tags instanceof Set; // trueRelated packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.