Skip to content

parse

parse(text, options?): unknown

Defined in: src/core.ts:638

Parse a single YAML document into a JavaScript value.

Reads exactly one document — like JSON.parse and js-yaml’s load. If text contains more than one ----separated document (or any trailing content after the first), parse throws rather than silently returning the first; use parseAll for multi-document streams. Plain scalars are typed per the YAML 1.2 core schema (1 is a number, true a boolean, null/~/empty a null); an empty document is null.

string

The YAML source text.

ParseOptions

Optional ParseOptions; omitting it (the default) leaves parsing byte-for-byte unchanged.

unknown

The document’s value: an object, array, string, number, boolean, or null.

YAMLParseError if text is not well-formed YAML, or contains more than one document.

parse("dish: pancakes\nserves: 4")
// { dish: "pancakes", serves: 4 }