## Usage ```js var writeJson = require('{%= name %}'); // async writeJson('foo.json', {abc: 'xyz'}, function(err) { // do stuff with err }); // sync writeJson.sync('foo.json', {abc: 'xyz'}); ```
JSON.stringify ### arguments All methods support the same arguments as [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) (note that if you want to pass a [replacer][] function to `writeJson` - the main export, you must pass the replacer on an [options](#options) object) ```js // async writeJson('foo.json', {abc: 'xyz'}, null, 2, function(err) { if (err) console.log(err); }); // sync writeJson.sync('foo.json', {abc: 'xyz'}, null, 2); ``` ### options Or as an options object: ```js var options = { replacer: function(key, value) { // filter out properties if (typeof value === 'string') { return undefined; } return value; }, indent: 2 }; // async writeJson('foo.json', {abc: 'xyz'}, options, function(err) { if (err) console.log(err); }); // sync writeJson.sync('actual/test.json', expected, options); ```
## API {%= apidocs("index.js") %} ## Release history ### v2.0.0 - 2017-07-10 **Changed** - The main function now returns a promise if no callback is passed **Added** - adds [promise support](#promise) - adds [stream support](#stream) ### v1.0.0 - 2017-04-12 **Fixed** - Make sure `JSON.stringify` receives all intended arguments [replacer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter [writestream]: https://nodejs.org/api/fs.html#fs_class_fs_writestream