outputJson-sync.md 617 B

outputJsonSync(file, object, [options])

Almost the same as writeJsonSync, except that if the directory does not exist, it's created. options are what you'd pass to jsonFile.writeFileSync().

Alias: outputJSONSync()

  • file <String>
  • object <Object>
  • options <Object>

Example:

const fs = require('fs-extra')

const file = '/tmp/this/path/does/not/exist/file.json'
fs.outputJsonSync(file, {name: 'JP'})

const data = fs.readJsonSync(file)
console.log(data.name) // => JP