Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stringify and write JSON to a file atomically

License

NotificationsYou must be signed in to change notification settings

sindresorhus/write-json-file

Repository files navigation

Stringify and write JSON to a fileatomically

Creates directories for you as needed.

Install

npm install write-json-file

Usage

import{writeJsonFile}from'write-json-file';awaitwriteJsonFile('foo.json',{foo:true});

API

writeJsonFile(filePath, data, options?)

Returns aPromise.

writeJsonFileSync(filePath, data, options?)

options

Type:object

indent

Type:string | number | undefined
Default:'\t'

Indentation as a string or number of spaces.

Pass inundefined for no formatting.

If you set both this anddetectIndent, 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 acompare function.

replacer

Type:Function

Passed intoJSON.stringify.

mode

Type:number
Default:0o666

Themode used when writing the file.

Related

About

Stringify and write JSON to a file atomically

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp