1 | # load-json-file
|
2 |
|
3 | > Read and parse a JSON file
|
4 |
|
5 | It 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
|
16 | import {loadJsonFile} from 'load-json-file';
|
17 |
|
18 | console.log(await loadJsonFile('foo.json'));
|
19 | //=> {foo: true}
|
20 | ```
|
21 |
|
22 | ## API
|
23 |
|
24 | ### loadJsonFile(filePath, options?)
|
25 |
|
26 | Returns a `Promise<unknown>` with the parsed JSON.
|
27 |
|
28 | ### loadJsonFileSync(filepath, options?)
|
29 |
|
30 | Returns the parsed JSON.
|
31 |
|
32 | #### options
|
33 |
|
34 | Type: `object`
|
35 |
|
36 | ##### beforeParse
|
37 |
|
38 | Type: `Function`
|
39 |
|
40 | Applies a function to the JSON string before parsing.
|
41 |
|
42 | ##### reviver
|
43 |
|
44 | Type: `Function`
|
45 |
|
46 | Prescribes 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 |
|
50 | Available as part of the Tidelift Subscription.
|
51 |
|
52 | The 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
|