YAML in JavaScript / TypeScript
Direct answer
In JavaScript / TypeScript, load YAML with a maintained library such as js-yaml, prefer safe/typed APIs for untrusted input, and validate files before deploy.
Libraries
Common choice: js-yaml.
Safe load example
npm install js-yaml
import yaml from 'js-yaml';
const doc = yaml.load(text);Common pitfalls
- Prefer DEFAULT_SCHEMA consciously for 1.2 behavior
- Validate before load in production pipelines
- Browser tools on YAML.cc use js-yaml
Related
Validation tips
- Unit-test loading of fixture YAML in CI.
- Reject documents that fail safe/typed parse.
- Cross-check ambiguous scalars with the 1.1 vs 1.2 guide.
- Use the browser validator for quick private checks.
When not to use YAML
If you need comment-preserving round trips, binary data, or strict schema-first APIs, consider whether JSON Schema + JSON, or a purpose-built config format, fits better — then convert only at boundaries.