1 | # outputJsonSync(file, object, [options])
|
2 |
|
3 | Almost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created.
|
4 |
|
5 | **Alias:** `outputJSONSync()`
|
6 |
|
7 | - `file` `<String>`
|
8 | - `object` `<Object>`
|
9 | - `options` `<Object>`
|
10 | - `spaces` `<Number|String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.
|
11 | - `EOL` `<String>` Set EOL character. Default is `\n`.
|
12 | - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
|
13 | - Also accepts [`fs.writeFileSync` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
|
14 |
|
15 | ## Example:
|
16 |
|
17 | ```js
|
18 | const fs = require('fs-extra')
|
19 |
|
20 | const file = '/tmp/this/path/does/not/exist/file.json'
|
21 | fs.outputJsonSync(file, {name: 'JP'})
|
22 |
|
23 | const data = fs.readJsonSync(file)
|
24 | console.log(data.name) // => JP
|
25 | ```
|