UNPKG

1.57 kBMarkdownView Raw
1# load-json-file
2
3> Read and parse a JSON file
4
5It also [strips UTF-8 BOM](https://github.com/sindresorhus/strip-bom).
6
7## Install
8
9```
10$ npm install load-json-file
11```
12
13## Usage
14
15```js
16import {loadJsonFile} from 'load-json-file';
17
18console.log(await loadJsonFile('foo.json'));
19//=> {foo: true}
20```
21
22## API
23
24### loadJsonFile(filePath, options?)
25
26Returns a `Promise<unknown>` with the parsed JSON.
27
28### loadJsonFileSync(filepath, options?)
29
30Returns the parsed JSON.
31
32#### options
33
34Type: `object`
35
36##### beforeParse
37
38Type: `Function`
39
40Applies a function to the JSON string before parsing.
41
42##### reviver
43
44Type: `Function`
45
46Prescribes how the value originally produced by parsing is transformed, before being returned. See the [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more.
47
48## load-json-file for enterprise
49
50Available as part of the Tidelift Subscription.
51
52The maintainers of load-json-file and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-load-json-file?utm_source=npm-load-json-file&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
53
54## Related
55
56- [write-json-file](https://github.com/sindresorhus/write-json-file) - Stringify and write JSON to a file atomically