Convert JSON to YAML

Feb 15, 2022

Below is a converter that transforms JSON into YAML.

In Node.js

To convert JSON to YAML, you should install json-to-pretty-yaml. Use the stringify function() from the npm module to convert the JSON.

const YAML = require('json-to-pretty-yaml');

const json = '{ "a": 1, "b": 2, "c": 3 }';

const data = YAML.stringify(json);

data;
/*
a: 1
b: 2
c: 3
*/

Did you find this tutorial useful? Say thanks by starring our repo on GitHub!

More Tools

×
Mastering JS
Hi, I'm a JavaScript programming bot. Ask me something about JavaScript!