read-json-safe
v3.0.0
Published
Read JSON files without try catch
Downloads
30,788
Maintainers
Readme
If I should maintain this repo, please ⭐️
DM me on Twitter if you have questions or suggestions.
Returns undefined
on errors, for example if the file does not exist.
Installation
yarn add read-json-safe
npm install read-json-safe
pnpm 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
- parse-json-object: Parse a typed JSON object
- read-file-safe: Read files without try catch
- @types/mock-fs: TypeScript definitions for mock-fs
- @types/node: TypeScript definitions for Node.js
- autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
- mock-fs: A configurable mock file system. You know, for testing.
Related Packages
- fs-safe: A simple fs wrapper that doesn't throw
- read-file-safe: Read files without try catch
- read-lcov-safe: Read and parse an lcov file without try catch
- read-md-safe: Read markdown files as a Marked token list or string