# write-json-safe

> Write formatted JSON to a file

Latest version **4.0.0** (published 2023-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install write-json-safe
pnpm add write-json-safe
yarn add write-json-safe
bun add write-json-safe
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-01-24 |
| First published | 2020-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Connor White |
| Maintainers | bconnorwhite |
| Keywords | write, file, json, safe, pretty, formatted, format, output, recursive, parent, newline |

## Links

- npm: https://www.npmjs.com/package/write-json-safe
- Repository: https://github.com/bconnorwhite/write-json-safe
- Homepage: https://connorwhite.dev/github/write-json-safe
- Issues: https://github.com/bconnorwhite/write-json-safe/issues
- npm.io page: https://npm.io/package/write-json-safe

## Dependencies (2)

- [write-file-safe](https://npm.io/package/write-file-safe.md) ^2.0.1
- [stringify-json-object](https://npm.io/package/stringify-json-object.md) ^3.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-01-24
- 3.0.0 — 2023-01-18
- 2.1.0 — 2021-04-13
- 2.0.2 — 2021-04-06
- 2.0.1 — 2020-10-04
- 2.0.0 — 2020-10-04
- 1.0.1 — 2020-09-03
- 1.0.0 — 2020-08-28

## README

<!--BEGIN HEADER-->
<div id="top" align="center">
  <h1>write-json-safe</h1>
  <a href="https://npmjs.com/package/write-json-safe">
    <img alt="NPM" src="https://img.shields.io/npm/v/write-json-safe.svg">
  </a>
  <a href="https://github.com/bconnorwhite/write-json-safe">
    <img alt="TypeScript" src="https://img.shields.io/github/languages/top/bconnorwhite/write-json-safe.svg">
  </a>
  <a href="https://coveralls.io/github/bconnorwhite/write-json-safe?branch=master">
    <img alt="Coverage Status" src="https://img.shields.io/coveralls/github/bconnorwhite/write-json-safe.svg?branch=master">
  </a>
</div>

<br />

<blockquote align="center">Write formatted JSON to a file.</blockquote>

<br />

_If I should maintain this repo, please ⭐️_
<a href="https://github.com/bconnorwhite/write-json-safe">
  <img align="right" alt="GitHub stars" src="https://img.shields.io/github/stars/bconnorwhite/write-json-safe?label=%E2%AD%90%EF%B8%8F&style=social">
</a>

_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._
<a href="https://twitter.com/bconnorwhite">
  <img align="right" alt="Twitter" src="https://img.shields.io/twitter/url?label=%40bconnorwhite&style=social&url=https%3A%2F%2Ftwitter.com%2Fbconnorwhite">
</a>

---
<!--END HEADER-->

## 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<boolean>;

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;
};
```

<!--BEGIN FOOTER-->

<br />

<h2 id="dependencies">Dependencies<a href="https://www.npmjs.com/package/write-json-safe?activeTab=dependencies"><img align="right" alt="dependencies" src="https://img.shields.io/librariesio/release/npm/write-json-safe.svg"></a></h2>

- [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

<br />

<h3>Dev Dependencies</h3>

- [@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


<br />

<h2 id="license">License <a href="https://opensource.org/licenses/MIT"><img align="right" alt="license" src="https://img.shields.io/npm/l/write-json-safe.svg"></a></h2>

[MIT](https://opensource.org/licenses/MIT)
<!--END FOOTER-->

<br />

## 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

---
_Source: https://npm.io/package/write-json-safe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
