writeJson-sync

writeJsonSync(file, object[, options])

将对象写入JSON文件。

Alias: writeJSONSync()

  • file <String>
  • object <Object>
  • options <Object>
    • spaces <Number> | <String> 要缩进的空格数;或用于缩进的字符串(即传递“\t”用于制表符缩进)。有关更多信息,请参阅文档
    • EOL <String> 设置EOL字符。默认值为\n。
    • replacer JSON replacer
    • 也接受 [fs.writeFileSync()](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) options

Example:

1
2
3
const fs = require('fs-extra')

fs.writeJsonSync('./package.json', {name: 'fs-extra'})

另请参见**:** [outputJsonSync()](outputJson-sync.md)