npm.io
4.0.0 • Published 6 months ago

read-json-safe

Licence
MIT
Version
4.0.0
Deps
3
Size
9 kB
Vulns
0
Weekly
0
Stars
1

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
npm install read-json-safe
Yarn
yarn add read-json-safe
PNPM
pnpm add read-json-safe
Bun
bun add read-json-safe

Usage

Read a JSONValue:
import { readJSON, readJSONSync, JSONValue } from "read-json-safe";

readJSON("file.json"); // Promise<JSONValue | undefined>
readJSONSync("file.json"); // JSONValue | undefined
Read a JSONObject:
import { readJSONObject, readJSONObjectSync, JSONObject } from "read-json-safe";

readJSONObject("file.json"); // Promise<JSONObject | undefined>
readJSONObjectSync("file.json"); // JSONObject | undefined
Read a JSONArray:
import { readJSONArray, readJSONArraySync, JSONArray } from "read-json-safe";

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

License license

MIT - MIT License


Keywords