# yaml — card for AI agents

JavaScript YAML parser and stringifier with full spec compliance.

Category: Utilities · npm package `yaml` · latest version 2.9.1 (checked 2026-11-01)
Install: `npm install yaml`
License: ISC (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## yaml
- Use `parse` / `stringify` from `yaml` for plain reads and writes. Reviver and replacer arguments follow the JSON implementation.
- Handle errors around `YAML.parse`: it throws on error and may log warnings with `console.warn`.
- Use `parseAllDocuments` for input with more than one YAML document. `parse` only supports a single document.
- To write a stream of documents, call `stringify` once per document value and join the results with `...\n`. Each `stringify` result already ends with `\n`.
- Pass one options object to every call, since option categories do not overlap. Use `intAsBigInt: true` to get BigInt integers, or `schema: 'failsafe'` to keep scalars as strings.
- Do not rely on undocumented internals. They may change between minor versions.
- If the bundled typings fail on an older TypeScript compiler, set `skipLibCheck: true`.

## What it is
- yaml is a YAML parser and serialiser for JavaScript. It is published as `yaml` on npm under the ISC license, and the GitHub repository was created on 2018-01-29. The README calls it "a definitive library for YAML" and says it supports both YAML 1.1 and YAML 1.2. The latest listed release, v2.9.1, limits recursive merge aliases and simplifies line unfolding during quoted string parsing.
- The README describes three API layers. `parse` and `stringify` work, "as far as possible", the same as `JSON.parse` and `JSON.stringify`. The README says the Documents layer "gets you all the bells and whistles supported by the library along with a decent AST". Its `Document` class lists `#directives`, `#errors` and `#warnings`. The Lexer, Parser and Composer layer "lets you get progressively closer to YAML source". A command-line tool is also included.

## Caveats
- parse() throws and takes one document: The docs say `YAML.parse` throws on error and may log warnings with `console.warn`. It only accepts a single YAML document. For multi-document input, use `parseAllDocuments`.
- Unrendered {{ }} templates come back mangled, with no error: FormatArc reports that a Helm-style value starting with `{{` produced no error in eemeli/yaml. The parser silently returned a mangled object. The post gives two fixes: quote the whole value, or validate only after the template is rendered.
- README and docs site disagree: The README says the minimum TypeScript version for the typings is 5.9. The docs site says 3.9. The README says the library accepts "any string" without throwing, while the site says "nearly any string". The README installs `yaml@next` with `--save-exact`, and the site uses plain `npm install yaml`.
- Only documented APIs are semver-protected: Breaking a documented API counts as a semver-major change. Undocumented internals may change between minor versions.

## Numbers (AgentGid data)
- Gid Score: 70.0 (#385 of all tools, 39 of 408 in its category)
- Used in 214 public projects set up for AI coding agents (3.4%)
- Downloads last week: 330,301,968 (as of 2026-11-24), +42.7% over 4 weeks
- GitHub stars: 1,705 (as of 2026-11-24)
- Last push: 2026-09-23

## Often used with
Vitest 63.6%, tsx 52.8%, TypeScript 88.8%, Model Context Protocol SDK (JavaScript) 33.6%, chalk 29.0%, Zod 54.2%

## Checked alternatives (same job)
- js-yaml: https://agentgid.com/tools/js-yaml/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/yaml/
- Homepage: https://eemeli.org/yaml/
- Repository: https://github.com/eemeli/yaml
- Source: https://github.com/eemeli/yaml#readme
- Source: https://github.com/eemeli/yaml
- Source: https://github.com/eemeli/yaml/releases
- Source: https://eemeli.org/yaml


## yaml: read, write and edit YAML files in JavaScript

yaml is a free JavaScript library that reads and writes YAML, the plain-text format many settings files are written in. Your app or script can load such a file, change one value and save it back with the comments people wrote still in place. It works in Node.js and in modern browsers.

### Where to use it
- Load a settings file: A Node.js script or server reads its settings from a YAML file and gets plain JavaScript objects and lists back.
- Change a value, keep the comments: Your tool bumps a port or a version number in a hand-written settings file, and the notes people left in it stay where they were.
- Save app data as a readable file: An export button or a generator script writes settings or content as YAML that a person can open and edit by hand.
- Point to the broken line: When a person pastes or uploads a broken settings file, your app shows which line and column are wrong instead of a vague failure.
- Read older files the old way: Files written for older tools treat words like yes, no and on as true or false; you can tell yaml to read them by the older rules.
- A settings editor in the browser: An admin page lets people edit a YAML settings file right in the browser and checks it before saving, with no server step. (idea, not from the official pages)

### How to start
- Add the package to your project (version 2; the GitHub front page already describes the next major version).

```
npm install yaml
```

- Import parse and stringify; they work like the built-in JSON functions.

```
import { parse, stringify } from 'yaml'
```

- To edit a file and keep its comments, parse it as a document instead.

```
import { parseDocument } from 'yaml'
```


### License
Free to use, change and share for any purpose, also in paid products, under the ISC license. Keep its copyright and license notice in copies you ship.

### Good to know
- The quick parse function stops with an error on a broken file, so your app should catch it and show the message.
- The quick parse function reads one document per file; files with several parts split by --- need parseAllDocuments.
- By default it follows the newer YAML 1.2 rules, where only true and false mean yes or no; words like yes, no and on stay text.
- It limits repeated references inside a file by default, which protects your server from files built to eat memory.
- Version 2.9.1 is the current release; a version 3 is in testing and needs a newer Node.js.

Checked 2026-11-10 against: https://github.com/eemeli/yaml/blob/v2.9.1/README.md, https://github.com/eemeli/yaml/blob/main/README.md, https://github.com/eemeli/yaml/blob/v2.9.1/LICENSE, https://eemeli.org/yaml/, https://registry.npmjs.org/yaml, https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz

### Mistakes to avoid
- Don't: Following the GitHub main-branch README (npm install --save-exact yaml@next) in a project on yaml 2 → Do: npm install yaml (2.9.1) and read the yaml@2 documentation site linked from the package (The main branch already describes the version 3 prerelease, which needs a newer Node.js.)
- Don't: stringify(parse(file)) to change one value in a hand-written config → Do: parseDocument(file), doc.setIn([...], value), then doc.toString() (parse returns plain data without comments; the Document keeps them (our demo kept both comments).)
- Don't: Expecting yes, no, on or NO to come back as true or false (old YAML 1.1 habit) → Do: Write true or false in the file, or parse with { version: '1.1' } for old files (Default rules are YAML 1.2; in our run NO stayed "NO" and became false only with version: '1.1'.)
- Don't: parse() on a file with several documents separated by --- → Do: parseAllDocuments(file) and read each document (parse supports one document per input.)
- Don't: Setting maxAliasCount to -1 for files that users upload → Do: Keep the default limit (100) for any input you do not control (The limit is what stops alias-expansion files from exhausting memory.)

### Questions
- Can I use it in a paid, closed-source app? Yes. The ISC license allows any use with or without a fee; keep the copyright and license notice.
- Does it keep comments when I save a file? Yes, if you edit through parseDocument and save with toString(); the quick parse and stringify functions give plain data without comments.
- Why does NO (Norway) or yes stay text? By default yaml reads files by the YAML 1.2 rules, where only true and false are true or false. Pass version '1.1' to read files written for older tools.
- Does it run in the browser? Yes. It has no other packages it depends on and runs in Node.js and in modern browsers.
- Is it maintained? Yes. Version 2.9.1 was published on 11 September 2026, and a version 3 is in prerelease.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
