https://github.com/bconnorwhite/write-json-safe
Write formatted JSON to a file, and create parent directories if necessary.
https://github.com/bconnorwhite/write-json-safe
json node nodejs typescript
Last synced: 2 months ago
JSON representation
Write formatted JSON to a file, and create parent directories if necessary.
- Host: GitHub
- URL: https://github.com/bconnorwhite/write-json-safe
- Owner: bconnorwhite
- Created: 2020-08-28T03:32:33.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T18:51:13.000Z (over 3 years ago)
- Last Synced: 2025-10-27T23:33:43.000Z (8 months ago)
- Topics: json, node, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 362 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
Write formatted JSON to a file.
_If I should maintain this repo, please ⭐️_
_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._
---
## Installation
```sh
yarn add write-json-safe
```
```sh
npm install write-json-safe
```
```sh
pnpm add write-json-safe
```
## Usage
```ts
import { writeJSON, writeJSONSync, Options, OptionalJSONValue } from "write-json-safe";
function writeJSON(path: string, content?: OptionalJSONValue, options?: Options): Promise;
function writeJSONSync(path: string, content?: OptionalJSONValue, options?: Options): boolean;
type Options = {
/**
* Output formatted JSON. Default: `true`
*/
pretty?: boolean;
/**
* Recursively create parent directories if needed. Default: `true`
*/
recursive?: boolean;
/**
* Ensure file ends with a newline. Default: `true`
*/
appendNewline?: boolean;
/**
* Write even if file already exists. Default: `true`
*/
overwrite?: boolean;
};
```
Dependencies
- [stringify-json-object](https://www.npmjs.com/package/stringify-json-object): Stringify and format a JSON object
- [write-file-safe](https://www.npmjs.com/package/write-file-safe): Write files atomically, and create parent directories if necessary
Dev Dependencies
- [@types/mock-fs](https://www.npmjs.com/package/@types/mock-fs): TypeScript definitions for mock-fs
- [autorepo](https://www.npmjs.com/package/autorepo): Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
- [mock-fs](https://www.npmjs.com/package/mock-fs): A configurable mock file system. You know, for testing.
- [read-file-safe](https://www.npmjs.com/package/read-file-safe): Read files without try catch
License
[MIT](https://opensource.org/licenses/MIT)
## Related Packages
- [types-json](https://www.npmjs.com/package/types-json): Type checking for JSON values
- [fs-safe](https://www.npmjs.com/package/fs-safe): A simple fs wrapper that doesn't throw
- [read-json-safe](https://www.npmjs.com/package/read-json-safe): Read JSON files without try catch
- [write-file-safe](https://www.npmjs.com/package/write-file-safe): Write files, and create parent directories if necessary
- [write-md-safe](https://www.npmjs.com/package/write-md-safe): Write markdown files from a [Marked](https://www.npmjs.com/package/marked) token list or string