{"name":"write-json","description":"Write a JSON to file disk, also creates directories in the dest path if they don't already exist.","version":"0.2.0","homepage":"https://github.com/jonschlinkert/write-json","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git://github.com/jonschlinkert/write-json.git"},"bugs":{"url":"https://github.com/jonschlinkert/write-json/issues"},"license":{"type":"MIT","url":"https://github.com/jonschlinkert/write-json/blob/master/LICENSE"},"files":["index.js"],"main":"index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"dependencies":{"write":"^0.2.0"},"keywords":["file","fs","json","object","package","path","pkg","stringify","write"],"devDependencies":{"delete":"^0.1.5","mocha":"^2.2.1","should":"^5.2.0"},"gitHead":"6108a60c6ea29d34c29361795d66186d6a8524d8","_id":"write-json@0.2.0","_shasum":"b2d49b4ae38b39cd1216ebc64401134e28798a85","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"dist":{"shasum":"b2d49b4ae38b39cd1216ebc64401134e28798a85","tarball":"http://registry-npm.ywwl.com/write-json/download/write-json-0.2.0.tgz","integrity":"sha512-nXInu5iazYELc9ZvXBnyYxKvvQHn520d/ZB9EIdaazjsXB4K40R7L1YSbbjW4LCT9wyGdqVV+Scw0ks4YGY1Pw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB2laqnHOdNxNo4JFADKl+imkx/2fMV5zVK5bIs0uDOjAiEAztWIlYMPwndOvPDXHVRd716/xCOTnoVsfRsR95G8370="}],"size":2127,"noattachment":false,"key":"/write-json/-/write-json-0.2.0.tgz"},"directories":{},"readme":"# write-json [![NPM version](https://img.shields.io/npm/v/write-json.svg?style=flat)](https://www.npmjs.com/package/write-json) [![NPM monthly downloads](https://img.shields.io/npm/dm/write-json.svg?style=flat)](https://npmjs.org/package/write-json) [![NPM total downloads](https://img.shields.io/npm/dt/write-json.svg?style=flat)](https://npmjs.org/package/write-json) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/write-json.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/write-json)\n\n> Write a JSON file to disk, also creates intermediate directories in the destination path if they don't already exist.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save write-json\n```\n\n## Usage\n\n```js\nvar writeJson = require('write-json'); \n\n// async\nwriteJson('foo.json', {abc: 'xyz'}, function(err) {\n  // do stuff with err\n});\n\n// sync\nwriteJson.sync('foo.json', {abc: 'xyz'});\n```\n\n<details>\n<summary><strong>JSON.stringify</strong></summary>\n\n### arguments\n\nAll 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) function to `writeJson` - the main export, you must pass the replacer on an [options](#options) object)\n\n```js\n// async\nwriteJson('foo.json', {abc: 'xyz'}, null, 2, function(err) {\n  if (err) console.log(err);\n});\n\n// sync\nwriteJson.sync('foo.json', {abc: 'xyz'}, null, 2);\n```\n\n### options\n\nOr as an options object:\n\n```js\nvar options = {\n  replacer: function(key, value) {\n    // filter out properties\n    if (typeof value === 'string') {\n      return undefined;\n    }\n    return value;\n  },\n  indent: 2\n};\n\n// async\nwriteJson('foo.json', {abc: 'xyz'}, options, function(err) {\n  if (err) console.log(err);\n});\n\n// sync\nwriteJson.sync('actual/test.json', expected, options);\n```\n\n</details>\n\n## API\n\n### [writeJson](index.js#L58)\n\nCalls `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.\n\n**Params**\n\n* `filepath` **{string}**: Destination file path\n* `value` **{object}**: Value to stringify.\n* `options` **{object}**: Options to pass to [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)\n* `callback` **{Function}**: (optional) If no callback is provided, a promise is returned.\n* `returns` **{undefined}**\n\n**Example**\n\n```js\nvar writeJson = require('write');\nvar pkg = {name: 'write-json'};\n\nwriteJson('foo.json', pkg, function(err) {\n  if (err) console.log(err);\n});\n\n// pass options to JSON.stringify explicitly\nwriteJson('foo.json', pkg, null, 2, function(err) {\n  if (err) console.log(err);\n});\n\n// pass options to JSON.stringify as an object\n// (since this method returns a promise if no callback is passed,\n// if you want to pass a replacer function to JSON.stringify, it\n// must be passed on an options object)\nwriteJson('foo.json', pkg, {\n  indent: 2,\n  replacer: function(value) {\n    // filter out properties\n    if (typeof value === 'string') {\n      return undefined;\n    }\n    return value;\n  }\n}, function(err) {\n  if (err) console.log(err);\n});\n```\n\n### [.promise](index.js#L84)\n\nThe promise version of [writeFile](#writefile). Returns a promise.\n\n**Params**\n\n* `filepath` **{String}**: Destination file path\n* `value` **{any}**: The value to stringify\n* `options` **{object}**: Options to pass to [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)\n* `returns` **{Promise}**\n\n**Example**\n\n```js\nvar writeJson = require('write');\nwriteJson.promise('package.json', {name: 'write-json'})\n  .then(function() {\n    // do stuff\n  });\n```\n\n### [.sync](index.js#L104)\n\nThe synchronous version of [writeFile](#writefile). Returns undefined.\n\n**Params**\n\n* `filepath` **{String}**: Destination file path\n* `value` **{any}**: The value to stringify\n* `options` **{object}**: Options to pass to [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)\n* `returns` **{undefined}**\n\n**Example**\n\n```js\nvar writeJson = require('write');\nwriteJson.sync('package.json', {name: 'write-json'});\n```\n\n### [.stream](index.js#L129)\n\nThe stream version of [writeFile](#writefile). Returns a new [WriteStream](https://nodejs.org/api/fs.html#fs_class_fs_writestream) object.\n\n**Params**\n\n* `filepath` **{string|Buffer|integer}**: filepath or file descriptor.\n* `options` **{object}**: Options to pass to [mkdirp](https://github.com/substack/node-mkdirp) and [fs.createWriteStream][fs]{#fs_fs_createwritestream_path_options}\n* `returns` **{Stream}**: Returns a new [WriteStream](https://nodejs.org/api/fs.html#fs_class_fs_writestream) object. (See [Writable Stream](https://nodejs.org/api/stream.html#stream_class_stream_writable)).\n\n**Example**\n\n```js\nvar fs = require('fs');\nvar writeJson = require('write');\nfs.createReadStream('defaults.json')\n  .pipe(writeJson.stream('package.json'))\n  .on('close', function() {\n    // do stuff\n  });\n```\n\n## Release history\n\n### v2.0.0 - 2017-07-10\n\n**Changed**\n\n* The main function now returns a promise if no callback is passed\n\n**Added**\n\n* adds [promise support](#promise)\n* adds [stream support](#stream)\n\n### v1.0.0 - 2017-04-12\n\n**Fixed**\n\n* Make sure `JSON.stringify` receives all intended arguments\n\n## About\n\n<details>\n<summary><strong>Contributing</strong></summary>\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n</details>\n\n<details>\n<summary><strong>Running Tests</strong></summary>\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install && npm test\n```\n\n</details>\n\n<details>\n<summary><strong>Building docs</strong></summary>\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme && verb\n```\n\n</details>\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [delete](https://www.npmjs.com/package/delete): Delete files and folders and any intermediate directories if they exist (sync and async). | [homepage](https://github.com/jonschlinkert/delete \"Delete files and folders and any intermediate directories if they exist (sync and async).\")\n* [read-data](https://www.npmjs.com/package/read-data): Read JSON or YAML files. | [homepage](https://github.com/jonschlinkert/read-data \"Read JSON or YAML files.\")\n* [read-yaml](https://www.npmjs.com/package/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files. | [homepage](https://github.com/jonschlinkert/read-yaml \"Very thin wrapper around js-yaml for directly reading in YAML files.\")\n* [write-data](https://www.npmjs.com/package/write-data): Write a YAML or JSON file to disk. Automatically detects the format to write based… [more](https://github.com/jonschlinkert/write-data) | [homepage](https://github.com/jonschlinkert/write-data \"Write a YAML or JSON file to disk. Automatically detects the format to write based on extension. Or pass `ext` on the options.\")\n* [write-yaml](https://www.npmjs.com/package/write-yaml): Write YAML. Converts JSON to YAML writes it to the specified file. | [homepage](https://github.com/jonschlinkert/write-yaml \"Write YAML. Converts JSON to YAML writes it to the specified file.\")\n* [write](https://www.npmjs.com/package/write): Write data to a file, replacing the file if it already exists and creating any… [more](https://github.com/jonschlinkert/write) | [homepage](https://github.com/jonschlinkert/write \"Write data to a file, replacing the file if it already exists and creating any intermediate directories if they don't already exist. Thin wrapper around node's native fs methods.\")\n\n### Author\n\n**Jon Schlinkert**\n\n* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on January 26, 2018._","publish_time":1428401875841,"_cnpm_publish_time":1428401875841,"dist-tags":{"latest":"3.0.1"}}