# read-json-safe

> Read JSON files without try catch

Latest version **4.0.0** (published 2026-03-11) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 65/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-03-11 |
| First published | 2020-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 3 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Connor White |
| Maintainers | bconnorwhite |
| Keywords | json, read, file, safe, try, catch, ENOENT |

## Links

- npm: https://www.npmjs.com/package/read-json-safe
- Repository: https://github.com/bconnorwhite/read-json-safe
- Homepage: https://github.bconnorwhite.com/read-json-safe#readme
- Issues: https://github.com/bconnorwhite/read-json-safe/issues
- npm.io page: https://npm.io/package/read-json-safe

## Dependencies (3)

- [types-json](https://npm.io/package/types-json.md) ^5.0.0
- [read-file-safe](https://npm.io/package/read-file-safe.md) ^2.1.1
- [parse-json-object](https://npm.io/package/parse-json-object.md) ^3.0.1

## 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) — 2026-03-11
- 3.0.0 — 2023-01-30
- 2.0.2 — 2020-10-04
- 2.0.1 — 2020-10-04
- 2.0.0 — 2020-10-04
- 1.0.5 — 2020-09-03
- 1.0.4 — 2020-09-02
- 1.0.3 — 2020-09-02
- 1.0.2 — 2020-08-28
- 1.0.1 — 2020-08-16
- 1.0.0 — 2020-08-16

## README

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

<br />

<blockquote align="center">Read JSON files without try catch.</blockquote>


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

Returns `undefined` on errors, for example if the file does not exist.

## Installation

<details open>
  <summary>
    <a href="https://www.npmjs.com/package/read-json-safe">
      <img src="https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white" alt="NPM" />
    </a>
  </summary>

```sh
npm install read-json-safe
```

</details>

<details>
  <summary>
    <a href="https://yarnpkg.com/package/read-json-safe">
      <img src="https://img.shields.io/badge/yarn-2C8EBB?logo=yarn&logoColor=white" alt="Yarn" />
    </a>
  </summary>

```sh
yarn add read-json-safe
```

</details>

<details>
  <summary>
    <img src="https://img.shields.io/badge/pnpm-F69220?logo=pnpm&logoColor=white" alt="PNPM" />
  </summary>

```sh
pnpm add read-json-safe
```

</details>

<details>
  <summary>
    <img src="https://img.shields.io/badge/bun-EE81C3?logo=bun&logoColor=white" alt="Bun" />
  </summary>

```sh
bun add read-json-safe
```

</details>


## Usage

### Read a JSONValue:

```ts
import { readJSON, readJSONSync, JSONValue } from "read-json-safe";

readJSON("file.json"); // Promise<JSONValue | undefined>
readJSONSync("file.json"); // JSONValue | undefined
```

### Read a JSONObject:

```ts
import { readJSONObject, readJSONObjectSync, JSONObject } from "read-json-safe";

readJSONObject("file.json"); // Promise<JSONObject | undefined>
readJSONObjectSync("file.json"); // JSONObject | undefined
```

### Read a JSONArray:

```ts
import { readJSONArray, readJSONArraySync, JSONArray } from "read-json-safe";

readJSONArray("file.json"); // Promise<JSONArray | undefined>
readJSONArraySync("file.json"); // JSONArray | undefined
```

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

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

<br />

## Related Packages

- [fs-safe](https://www.npmjs.com/package/fs-safe): A simple fs wrapper that doesn't throw
- [read-file-safe](https://www.npmjs.com/package/read-file-safe): Read files without try catch
- [read-lcov-safe](https://www.npmjs.com/package/read-lcov-safe): Read and parse an lcov file without try catch
- [read-md-safe](https://www.npmjs.com/package/read-md-safe): Read markdown files as a [Marked](https://www.npmjs.com/package/marked) token list or string

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