Seria is a serialization and deserialization library that goes beyond the conventional capabilities of JSON. It provides seamless handling for various data types, including those that JSON cannot handle directly.
This library is inspired on the new serialization capabilities
react
provides for server actions.
npm install seria
yarn add seria
pnpm add seria
import * as seria from "seria";
const json = seria.stringify(value);
const value = seria.parse(json);
Seria also supports encoding and decoding FormData:
import { encode, decode } from "seria/form-data";
const formData = encode(value);
const value = decode(formData);
Seria provides stream-based serialization and deserialization:
import * as seria from "seria";
const stream = seria.stringifyToStream(value);
const result = await seria.parseFromStream(stream);
If you serialize a value that contains any Promise
you need to serialize using a stream or use seria.stringifyAsync
which resolve all the promises.
Types supported by seria
in comparison with the standard JSON
object.
Data Type | seria.stringify/parse | JSON.stringify/parse |
---|---|---|
string | ✅ | ✅ |
number | ✅ | ✅ |
boolean | ✅ | ✅ |
null | ✅ | ✅ |
undefined | ✅ | ❌ |
Date | ✅ | ❌ |
BigInt | ✅ | ❌ |
Promise | ✅ | ❌ |
Symbol | ✅ | ❌ |
Set | ✅ | ❌ |
Map | ✅ | ❌ |
ArrayBuffer | ✅ | ❌ |
Int8Array | ✅ | ❌ |
Uint8Array | ✅ | ❌ |
Uint8ClampedArray | ✅ | ❌ |
Int16Array | ✅ | ❌ |
Uint16Array | ✅ | ❌ |
Int32Array | ✅ | ❌ |
Uint32Array | ✅ | ❌ |
Float32Array | ✅ | ❌ |
Float64Array | ✅ | ❌ |
BigInt64Array | ✅ | ❌ |
BigUint64Array | ✅ | ❌ |
DataView | ✅ | ❌ |
File* | ✅ | ❌ |
FormData* | ✅ | ❌ |
File
andFormData
are supported onseria/form-data
.