{"id":15681695,"url":"https://github.com/jonschlinkert/write-json","last_synced_at":"2026-03-09T04:33:01.044Z","repository":{"id":24710178,"uuid":"28121847","full_name":"jonschlinkert/write-json","owner":"jonschlinkert","description":"Write a JSON to file disk, also creates directories in the dest path if they don't already exist.","archived":false,"fork":false,"pushed_at":"2018-01-26T21:56:34.000Z","size":25,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-09-18T01:39:28.554Z","etag":null,"topics":["data","disk","file","file-system","fs","json","object","write"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-17T05:00:24.000Z","updated_at":"2021-08-25T19:39:38.000Z","dependencies_parsed_at":"2022-07-15T13:47:17.782Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/write-json","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jonschlinkert/write-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwrite-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwrite-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwrite-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwrite-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/write-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwrite-json/sbom","scorecard":{"id":532202,"data":{"date":"2025-08-11","repo":{"name":"github.com/jonschlinkert/write-json","commit":"1159465425ab04f3a8748663fdb5dead306c2c2e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}}]},"last_synced_at":"2025-08-20T05:58:40.525Z","repository_id":24710178,"created_at":"2025-08-20T05:58:40.525Z","updated_at":"2025-08-20T05:58:40.525Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30283425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","disk","file","file-system","fs","json","object","write"],"created_at":"2024-10-03T16:58:41.549Z","updated_at":"2026-03-09T04:33:01.009Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","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\u0026label=Travis)](https://travis-ci.org/jonschlinkert/write-json)\n\n\u003e 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\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eJSON.stringify\u003c/strong\u003e\u003c/summary\u003e\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\u003c/details\u003e\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\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\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 \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\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 \u0026\u0026 verb\n```\n\n\u003c/details\u003e\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._","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fwrite-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fwrite-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fwrite-json/lists"}