Git Product home page Git Product logo

write-json-file's Introduction

write-json-file Build Status

Stringify and write JSON to a file atomically

Creates directories for you as needed.

Install

$ npm install write-json-file

Usage

const writeJsonFile = require('write-json-file');

(async () => {
	await writeJsonFile('foo.json', {foo: true});
})();

API

writeJsonFile(filePath, data, options?)

Returns a Promise.

writeJsonFile.sync(filePath, data, options?)

options

Type: object

indent

Type: string | number
Default: '\t'

Indentation as a string or number of spaces.

Pass in undefined for no formatting.

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

Mode used when writing the file.

write-json-file for enterprise

Available as part of the Tidelift Subscription.

The maintainers of write-json-file and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Related

write-json-file's People

Contributors

sindresorhus avatar kevva avatar coreyfarrell avatar linusu avatar samverschueren avatar deniscarriere avatar bendingbender avatar paulhayes avatar privatenumber avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.