js-yaml Examples You Can Edit and Run
4 small js-yaml examples written by AgentGid from the official docs, one feature each. Every one runs in your browser: change the code and see the result at once, or describe a change and let AI rewrite it. The screenshots are taken from the same code by our server, which also checks that each example starts without errors.
js-yaml: usage and stats 134 AI-built projects use it
Parse YAML with js-yaml load()Add a new key to the YAML text and print it with another console.log line.
Write YAML with js-yaml dump()Add another nested object to config and see how dump() indents it.
Handle YAML parse errors in js-yamlFix one of the broken snippets and watch it move from the error list to the OK list.
Update a YAML config with js-yamlChange a different field before dumping, for example set debug to true.
Try them all in one place
import { load } from 'js-yaml'
const text = `
greeting: hello
version: 3
enabled: true
server:
host: localhost
port: 8080
languages:
- en
- de
- ja
`
try {
const document = load(text)
console.log('greeting:', document.greeting)
console.log('version:', document.version, '(' + typeof document.version + ')')
console.log('enabled:', document.enabled, '(' + typeof document.enabled + ')')
console.log('server.host:', document.server.host)
console.log('server.port:', document.server.port)
console.log('languages:', document.languages.join(', '))
console.log('language count:', document.languages.length)
console.log('as JSON:', JSON.stringify(document))
} catch (e) {
console.log('error:', e.message)
}
Add a new key to the YAML text and print it with another console.log line. Code written by AgentGid [1]. How it works, with a screenshot →
Add a new key to the YAML text and print it with another console.log line. Code written by AgentGid [1]. How it works, with a screenshot →Add another nested object to config and see how dump() indents it. Code written by AgentGid [1]. How it works, with a screenshot →Fix one of the broken snippets and watch it move from the error list to the OK list. Code written by AgentGid [1]. How it works, with a screenshot →Change a different field before dumping, for example set debug to true. Code written by AgentGid [1]. How it works, with a screenshot →Checked Oct 12, 2026: each example starts without errors in Chromium with js-yaml 5.4.3. Needs WebGL.
Sources
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.