An open API service indexing awesome lists of open source software.

https://github.com/bconnorwhite/read-json-safe

Read objects from JSON files without try catch.
https://github.com/bconnorwhite/read-json-safe

json node nodejs typescript

Last synced: 3 months ago
JSON representation

Read objects from JSON files without try catch.

Awesome Lists containing this project

README

          


read-json-safe



NPM


TypeScript


Coverage Status


Read JSON files without try catch.

---

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

## Installation



NPM

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



Yarn

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


PNPM

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


Bun

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

## Usage

### Read a JSONValue:

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

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

### Read a JSONObject:

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

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

### Read a JSONArray:

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

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

License license

[MIT](https://opensource.org/licenses/MIT) - _MIT License_


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