Skip to content

stringify

stringify(value): string

Defined in: src/index.ts:581

Serialize a JavaScript value into a YAML document string (always ending in a trailing newline).

Emits block-style collections; strings, numbers, booleans and null become scalars, and a Uint8Array becomes a !!binary scalar. Values that share a reference — or form a cycle — are emitted once with an anchor (&) and referenced by alias (*) rather than duplicated, so parse(stringify(x)) reconstructs the same shared-reference graph rather than a deep copy.

unknown

The value to serialize.

string

The YAML document text.

stringify({ dish: "pancakes", ingredients: ["flour", "milk", "eggs"] })
// "dish: pancakes\ningredients:\n - flour\n - milk\n - eggs\n"