1 | # writeJsonSync(file, object, [options])
|
2 |
|
3 | Writes an object to a JSON file.
|
4 |
|
5 | **Alias:** `writeJSONSync()`
|
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 | fs.writeJsonSync('./package.json', {name: 'fs-extra'})
|
21 | ```
|
22 | ---
|
23 |
|
24 | **See also:** [`outputJsonSync()`](outputJson-sync.md)
|