Stringify and write JSON to a file atomically
Installations
npm install write-json-file
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.20.2
NPM Version
10.6.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (64.52%)
TypeScript (35.48%)
Developer
sindresorhus
Download Statistics
Total Downloads
763,164,026
Last Day
341,856
Last Week
2,015,126
Last Month
6,663,550
Last Year
115,539,481
GitHub Statistics
220 Stars
66 Commits
40 Forks
7 Watching
1 Branches
10 Contributors
Bundle Size
7.16 kB
Minified
2.86 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
6.0.0
Package Id
write-json-file@6.0.0
Unpacked Size
7.24 kB
Size
2.84 kB
File Count
5
NPM Version
10.6.0
Node Version
18.20.2
Publised On
26 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
763,164,026
Last day
-7.7%
341,856
Compared to previous day
Last week
1.3%
2,015,126
Compared to previous week
Last month
-31.6%
6,663,550
Compared to previous month
Last year
-21.1%
115,539,481
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
write-json-file
Stringify and write JSON to a file atomically
Creates directories for you as needed.
Install
1npm install write-json-file
Usage
1import {writeJsonFile} from 'write-json-file'; 2 3await writeJsonFile('foo.json', {foo: true});
API
writeJsonFile(filePath, data, options?)
Returns a Promise
.
writeJsonFileSync(filePath, data, options?)
options
Type: object
indent
Type: string | number | undefined
Default: '\t'
Indentation as a string or number of spaces.
Pass in undefined
for no formatting.
If you set both this and detectIndent
, this value will be used when the indentation cannot be detected.
detectIndent
Type: boolean
Default: false
Detect indentation automatically if the file exists.
sortKeys
Type: boolean | Function
Default: false
Sort the keys recursively.
Optionally pass in a compare
function.
replacer
Type: Function
Passed into JSON.stringify
.
mode
Type: number
Default: 0o666
The mode used when writing the file.
Related
- load-json-file - Read and parse a JSON file
- make-dir - Make a directory and its parents if needed
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/write-json-file/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/write-json-file/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More