index.js
function writeJson(filepath, value, cb) {
  var args = [].slice.call(arguments, 1);
  if (typeof args[args.length - 1] === 'function') {
    cb = args.pop();
  }
  return writeFile(filepath, stringify.apply(null, args), cb);
}
function writeJson(filepath, value, cb) {
  var args = [].slice.call(arguments, 1);
  if (typeof args[args.length - 1] === 'function') {
    cb = args.pop();
  }
  return writeFile(filepath, stringify.apply(null, args), cb);
}
function writeJson ( filepath , value , cb ) { var args = [ ] . slice . call ( arguments , 1 ) ; if ( typeof args [ args . length - 1 ] === 'function' ) { cb = args . pop ( ) ; } return writeFile ( filepath , stringify . apply ( null , args ) , cb ) ; }
Calls `JSON.stringify` on the given `value` then asynchronously writes the
result to a file, replacing the file if it already exists and creating any
intermediate directories if they don't already exist. Returns a promise if
a callback function is not passed.

```js
var writeJson = require('write');
var pkg = {name: 'write-json'};

writeJson('foo.json', pkg, function(err) {
if (err) console.log(err);
});

// pass options to JSON.stringify explicitly
writeJson('foo.json', pkg, null, 2, function(err) {
if (err) console.log(err);
});

// pass options to JSON.stringify as an object
// (since this method returns a promise if no callback is passed,
// if you want to pass a replacer function to JSON.stringify, it
// must be passed on an options object)
writeJson('foo.json', pkg, {
indent: 2,
replacer: function(value) {
// filter out properties
if (typeof value === 'string') {
return undefined;
}
return value;
}
}, function(err) {
if (err) console.log(err);
});
```
@name writeJson
@param  {string} `filepath` Destination file path
@param  {object} `value` Value to stringify.
@param  {object} `options` Options to pass to [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
@param  {Function} `callback` (optional) If no callback is provided, a promise is returned.
@return {undefined}
@api public
Calls JSON . stringify on the given value then asynchronously writes the result to a file replacing the file if it already exists and creating any intermediate directories if they don t already exist . Returns a promise if a callback function is not passed .