Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Write YAML with js-yaml dump()

dump() goes the other way from load(): it turns JavaScript data into YAML text, for example to write a config file.

All js-yaml examples js-yaml: usage and stats

Write YAML with js-yaml dump(): screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Call dump. dump(value) returns the YAML as a string. The README example dumps a one-key object; this one passes a nested object. [1]
  2. Print the YAML. The code prints the dumped text line by line so the indentation of nested objects and the list items are easy to see. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import { dump } from 'js-yaml'

console.log('simple:', JSON.stringify(dump({ greeting: 'hello' })))

const config = {
  name: 'docs-site',
  version: 2,
  draft: false,
  build: { command: 'npm run build', output: 'dist' },
  locales: ['en', 'fr'],
  authors: [
    { name: 'Ada', role: 'editor' },
    { name: 'Linus', role: 'reviewer' },
  ],
}

const source = dump(config)
console.log('--- dump(config) ---')
source.trimEnd().split('\n').forEach((line) => console.log(line))
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Add another nested object to config and see how dump() indents it. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with js-yaml 5.4.3. Needs WebGL.

More js-yaml examples

Parse YAML with js-yaml load() Handle YAML parse errors in js-yaml Update a YAML config with js-yaml

Sources

  1. js-yaml README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with js-yaml? Ask AgentGid →