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.
- Host: GitHub
- URL: https://github.com/bconnorwhite/read-json-safe
- Owner: bconnorwhite
- Created: 2020-08-16T03:32:30.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2026-03-11T19:13:18.000Z (4 months ago)
- Last Synced: 2026-03-11T22:36:31.916Z (4 months ago)
- Topics: json, node, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 351 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
Read JSON files without try catch.
---
Returns `undefined` on errors, for example if the file does not exist.
## Installation
```sh
npm install read-json-safe
```
```sh
yarn add read-json-safe
```
```sh
pnpm add read-json-safe
```
```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
[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