# js-yaml — card for AI agents

Fast YAML parser and serializer for JavaScript with spec compliance.

Category: Utilities · npm package `js-yaml` · latest version 5.5.0 (checked 2026-11-01)
Install: `npm install js-yaml`
License: MIT (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.

## Numbers (AgentGid data)
- Gid Score: 73.2 (#262 of all tools, 19 of 408 in its category)
- Used in 143 public projects set up for AI coding agents (2.3%)
- Downloads last week: 409,452,192 (as of 2026-11-24), +34.5% over 4 weeks
- GitHub stars: 6,641 (as of 2026-11-24)
- Last push: 2026-10-27

## Often used with
Prettier 49.0%, Model Context Protocol SDK (JavaScript) 32.2%, ESLint 60.8%, TypeScript 72.7%, Ajv 22.4%, esbuild 21.0%

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

## Links
- AgentGid page: https://agentgid.com/tools/js-yaml/
- Homepage: https://github.com/nodeca/js-yaml#readme
- Repository: https://github.com/nodeca/js-yaml


## js-yaml: read and write YAML files in JavaScript

js-yaml is a free JavaScript library that turns YAML text, the format of many settings files, into data your app can use, and turns data back into YAML. It works in Node.js and in the browser. Version 5 changed several defaults, so older examples can mislead.

### Where to use it
- Read a settings file: Your app keeps its name, port and options in config.yml; it reads the file at start and stops with a clear message if the file is broken.
- Write data out as YAML: Your tool creates a settings file, a workflow file or an export that people will read and edit by hand.
- Files with several documents: A deployment file holds several blocks split by --- lines; read them all as a list.
- Accept YAML that users upload: People paste or upload settings into your app; limit the size and treat any reading error as a rejected file.
- Settings at the top of blog posts: Markdown posts start with a short YAML block for title, date and tags; read it to build the post list. (idea, not from the official pages)
- A YAML to JSON converter page: A small page in your app turns pasted YAML into JSON and back, running fully in the visitor's browser. (idea, not from the official pages)

### How to start
- Add the package to your project.

```
npm install js-yaml
```

- Read YAML text with load() inside try/catch.

```
import { load } from 'js-yaml'

try {
  const document = load('greeting: hello')
  console.log(document.greeting)
} catch (e) {
  console.error(e)
}
```

- Write data as YAML text with dump().

```
import { dump } from 'js-yaml'

const source = dump({ greeting: 'hello' })
console.log(source)
```


### License
Free to use in any project, paid or not, under the MIT license. No visible credit is needed; keep the license notice with copies of its files.

### Good to know
- Broken files make load() stop with an error, so your code must catch it.
- A tiny file can expand into a huge object through repeated references. For files from strangers, limit the size and count items before using the data.
- Since version 5, an empty file is an error for load(); loadAll() still returns an empty list.
- Version 5 reads files by the newer YAML 1.2 rules, so dates stay text and "no" stays the word no.

Checked 2026-11-10 against: https://github.com/nodeca/js-yaml/blob/master/README.md, https://github.com/nodeca/js-yaml/blob/master/docs/usage.md, https://github.com/nodeca/js-yaml/blob/master/docs/safety.md, https://github.com/nodeca/js-yaml/blob/master/docs/migrate_v4_to_v5.md, https://github.com/nodeca/js-yaml/blob/master/docs/migrate_v3_to_v4.md, https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md, https://github.com/nodeca/js-yaml/blob/master/LICENSE, https://nodeca.github.io/js-yaml/doc/, https://registry.npmjs.org/js-yaml/5.5.0, https://eemeli.org/yaml/, https://registry.npmjs.org/gray-matter/latest

### Mistakes to avoid
- Don't: import yaml from 'js-yaml'; yaml.load(text) → Do: import { load, dump } from 'js-yaml' (or import * as yaml from 'js-yaml' to keep yaml.load calls) (Version 5 has no default export on purpose.)
- Don't: yaml.safeLoad(text) / yaml.safeDump(obj) → Do: load(text) / dump(obj); they are the safe versions (The safe* names were renamed in version 4 and removed in version 5.)
- Don't: load(text) on a file that uses <<: *base merge keys → Do: load(text, { schema: CORE_SCHEMA.withTags(mergeTag) }) (Merge keys are off by default in version 5; in our run the object kept a literal "<<" key instead of merging.)
- Don't: Expecting dates to become Date objects and yes/no to become true/false (version 4 habits) → Do: Parse dates yourself, or pass { schema: YAML11_SCHEMA } if you need the old YAML 1.1 types (Version 5 uses YAML 1.2 rules; in our run "when: 2026-11-10" stayed a string and "country: no" stayed "no".)
- Don't: version: 1.10 or zip: 012345 written without quotes → Do: Quote values that must stay text: version: '1.10', zip: '012345' (Unquoted they are read as numbers; in our run they became 1.1 and 12345.)

### Questions
- Where did safeLoad go? It was removed in version 5. load() has been the safe default since version 4, so call load() instead.
- Why does import yaml from 'js-yaml' fail? Version 5 has no default export. Use import { load, dump } from 'js-yaml', or import * as yaml from 'js-yaml'.
- Can it run in the browser? Yes. Browser builds are published under js-yaml/browser.
- My << merge keys stopped working after an upgrade. Why? Version 5 leaves merge keys off by default. Turn them on with CORE_SCHEMA.withTags(mergeTag).
- Is the project maintained? Yes. Version 5.5.0 came out on 2026-10-16, after the 5.0.0 rewrite in June 2026.

---
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.
