Silgi
Plugins

Custom Serializers

Extend JSON serialization for custom types — Date, BigInt, or your own classes.

Register custom type handlers that run during JSON stringify/parse. Useful when you need to preserve types that JSON.stringify drops.

Setup

import {  } from 'silgi/plugins'

const  = ()
  .('Date', {
    : () =>  instanceof ,
    : () => .toISOString(),
    : () => new (),
  })
  .('BigInt', {
    : () => typeof  === 'bigint',
    : () => .toString(),
    : () => (),
  })

Usage

// As JSON replacer/reviver
const  = .(data, serializer.replacer)
const  = .(, serializer.reviver)

// Or use the convenience methods
const  = serializer.stringify(data)
const  = serializer.parse()

Wire format

Custom types are wrapped during serialization:

{ "created": { "__$type": "Date", "__$value": "2026-01-01T00:00:00.000Z" } }

The reviver unwraps them back to the original type on parse.

When to use this vs devalue

ScenarioUse
Need Date, Map, Set, BigIntdevalue (built-in, zero config)
Need custom classes (Money, Decimal, etc.)Custom serializer
Need control over wire formatCustom serializer
Client and server both use Silgidevalue

What's next?

  • devalue — built-in rich type serialization
  • Plugins — other available plugins

On this page