YAML
YAML is way more complex than JSON. In fact, JSON syntax is included in YAML. YAML is quite human-readable π, so in some cases, it may be better to use YAML rather than JSON.
- List
# all are the same
list1:
- a
- b
- c
list2: [a, b, c]
list3: ['a', 'b', 'c']
- Keys
key1: value
key2: {}
key3:
- true
- 5
- "toto"
- Texts (inline and multiline texts)
inline: This is an inline text
multiline_text1: This is a really really really
long long text.
And this is still part of the text π.
multiline_text2: >
Same.
code: |+
preserve newlines and indents
Read YAML files in Node.js
js-yaml
js-yaml (6.1k β) is frequently updated.
const yaml = require('js-yaml');
const fs = require('fs');
const xxx = yaml.load(fs.readFileSync('test.yaml', 'utf8'));
console.log(xxx);
In TypeScript, you may use the following import:
// @ts-ignore
import { load } from 'js-yaml';
yamljs
yamljs (0.9k β) was not updated for years.
const YAML = require('yamljs');
const fs = require('fs');
const xxx = YAML.parse(fs.readFileSync('test.yaml', 'utf8'));
console.log(xxx)
π» To-do π»
Stuff that I found, but never read/used yet.
tags:
- xxx: &xxx "XXX"
entries:
yyy: *xxx