CodableJSON is a high-performance, no-dependency serializer that transforms JavaScript types to and from JSON with ease. Offering a TypeScript-friendly interface, it enables declarative serialization, making it robust yet simple to extend. Leverage its unique features to handle common JavaScript data structures seamlessly.
CodableJSON is an efficient, extensible, and declarative serializer designed to convert virtually any data structure to and from JSON format. By leveraging modern TypeScript features, it enables a high-performance experience while ensuring type safety and security. This library is free of external dependencies, with a compact size of only 7.3KB gzipped, making it an ideal choice for both small and large JavaScript/TypeScript projects.
Operate with JavaScript types that standard JSON does not natively support:
import { encode, decode } from "codablejson";
const data = {
date: new Date("2025-01-01"),
set: new Set(["a", "b", "c"]),
map: new Map([["key", "value"]]),
bigint: BigInt("1234567890123456789"),
regex: /hello/gi,
url: new URL("https://example.com"),
};
const encoded = encode(data);
const decoded = decode(encoded);
// All data types preserved during encoding and decoding.
Easily define classes for serialization while preserving their structure:
import { codableClass, codable, Coder } from "codablejson";
@codableClass("Player")
class Player {
@codable() name: string;
@codable() score: number;
constructor(data: Pick<Player, "name" | "score">) {
this.name = data.name;
this.score = data.score;
}
}
const coder = new Coder([Player]);
const playerInstance = new Player({ name: "Alice", score: 100 });
const encoded = coder.encode(playerInstance);
const decoded = coder.decode<Player>(encoded);
// Structure and types remain intact.
CodableJSON automatically handles multiple JavaScript data types that standard JSON serialization does not manage:
| JavaScript Type | Example Output |
|---|---|
Date | { $$Date: "2025-01-01T00:00:00.000Z" } |
BigInt | { $$BigInt: "1234567890123456789" } |
Set | { $$Set: ["a", "b", "c"] } |
Map | { $$Map: [["key", "value"]] } |
CodableJSON focuses on speed and efficiency, showcasing:
CodableJSON incorporates built-in security provisions to ensure safe serialization processes, such as filtering out dangerous properties and preventing prototype pollution.
For extensive documentation, including usage instructions, comparisons, and security best practices, please refer to the official documentation here.
No comments yet.
Sign in to be the first to comment.