Skip to content

Instantly share code, notes, and snippets.

@dsample
Created March 8, 2018 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsample/e8529d1a856d614df174c6c5cf59515f to your computer and use it in GitHub Desktop.
Save dsample/e8529d1a856d614df174c6c5cf59515f to your computer and use it in GitHub Desktop.
Convert a directory of YAML to JSON
const yaml = require('yamljs')
const fs = require('fs')
const directory = process.argv[2] || '.'
fs.readdirSync(directory)
.filter(f => f.endsWith('.yaml'))
.map(f => f.substring(0,f.indexOf('.yaml')))
.forEach((name) => {
const fromYaml = yaml.load(name + '.yaml')
const json = JSON.stringify(fromYaml,null,2)
fs.writeFile(name + '.json', json, () => {console.log(`Converted ${name}.yaml`)})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment