{"name":"write-json","description":"Write a JSON file to disk, also creates intermediate directories in the destination path if they don't already exist.","version":"3.0.1","homepage":"https://github.com/jonschlinkert/write-json","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/jonschlinkert/write-json.git"},"bugs":{"url":"https://github.com/jonschlinkert/write-json/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=4"},"scripts":{"test":"mocha"},"dependencies":{"isobject":"^3.0.1","write":"^1.0.3"},"devDependencies":{"delete":"^1.1.0","gulp-format-md":"^1.0.0","mocha":"^3.5.3"},"keywords":["async","buffer","data","file","file-system","filepath","files","filesystem","folder","format","fs","fs.createWriteStream","fs.writeFile","fs.writeFileSync","json","make-dir","make-dirp","mkdir","mkdirp","object","path","promise","read","stringify","sync","Uint8Array","write"],"verb":{"toc":false,"layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"related":{"list":["delete","read-data","read-yaml","write","write-data","write-yaml"]},"lint":{"reflinks":true}},"gitHead":"f7e856b8d1ea3acbea0afff26cb8db7782798936","_id":"write-json@3.0.1","_npmVersion":"5.6.0","_nodeVersion":"9.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"integrity":"sha512-PWscN8FOlnT0oSuN3vuq9FW2Wjwh3fqSRFgd75NHiHApIdi55bnbLI5nyFQwaiqEn73+w8B9NVC36SWHCKwHhw==","shasum":"6a5477dd01874e3c6af7e163414609a72d93bf56","tarball":"http://registry-npm.ywwl.com/write-json/download/write-json-3.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFlNbV234uvotpy+81wLD62lhFPSCm8MGwJEhSJ+HrZXAiEAkUZxu/tR0vNwlKCS0Bkn01l1t7upkssEyF2nTWLH+1o="}],"size":4727,"noattachment":false,"key":"/write-json/-/write-json-3.0.1.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/write-json-3.0.1.tgz_1517003780331_0.10371464840136468"},"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":1517003781354,"_cnpm_publish_time":1517003781354,"dist-tags":{"latest":"3.0.1"}}