shell
npm install js-yaml
script
const yaml = require('js-yaml');
script
const yamlData = `
name: John Doe
age: 30
email: johndoe@example.com`;
try {
const parsedData = yaml.load(yamlData);
console.log(parsedData);
} catch (error) {
console.log(error);
}
script
{
name: 'John Doe',
age: 30,
email: 'johndoe@example.com'
}
script
const userData = {
name: 'John Doe',
age: 30,
email: 'johndoe@example.com'
};
try {
const yamlData = yaml.dump(userData);
console.log(yamlData);
} catch (error) {
console.log(error);
}
script
'name: John Doe
age: 30
email: johndoe@example.com
'