Stringify and write JSON to a file atomically
npm install write-json-file> Stringify and write JSON to a file atomically
Creates directories for you as needed.
``sh`
npm install write-json-file
`js
import {writeJsonFile} from 'write-json-file';
await writeJsonFile('foo.json', {foo: true});
`
Returns a Promise.
#### options
Type: object
##### indent
Type: string | number | undefined\'\t'
Default:
Indentation as a string or number of spaces.
Pass in undefined for no formatting.
If you set both this and detectIndent, this value will be used when the indentation cannot be detected.
##### detectIndent
Type: boolean\false
Default:
Detect indentation automatically if the file exists.
##### sortKeys
Type: boolean | Function\false
Default:
Sort the keys recursively.
Optionally pass in a compare function.
##### replacer
Type: Function
Passed into JSON.stringify.
##### mode
Type: number\0o666`
Default:
The mode used when writing the file.
- load-json-file - Read and parse a JSON file
- make-dir - Make a directory and its parents if needed