V8

v8.serialize()

Encodes supported structured data to a Buffer. Unlike JSON it can preserve values such as Map and BigInt. Use a reviewed format for cross-service interoperability. Tested on Node.js 22.16.0. Example output (one line per entry): ["true true"].

Formal Syntax & Structure

nodejs syntaxnodejs
v8.serialize(value)

Parameters & Attributes

NameTypeDescription
valueunknownSerializable value.

Return Value

Buffer

Binary representation.

Working Example

Example Snippetnodejs
import { serialize, deserialize } from 'node:v8';const bytes = serialize(new Map([['stock', 9n]]));console.log(Buffer.isBuffer(bytes), deserialize(bytes).get('stock') === 9n);
Node.js Reference