load-json-file
Read and parse a JSON file
Last updated 9 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ cnpm install load-json-file 
SYNC missed versions from official npm registry.

load-json-file Build Status

Read and parse a JSON file

Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors.

Install

$ npm install load-json-file

Usage

const loadJsonFile = require('load-json-file');

(async () => {
	console.log(await loadJsonFile('foo.json'));
	//=> {foo: true}
})();

API

loadJsonFile(filePath, options?)

Returns a Promise<unknown> with the parsed JSON.

loadJsonFile.sync(filepath, options?)

Returns the parsed JSON.

options

Type: object

beforeParse

Type: Function

Applies a function to the JSON string before parsing.

reviver

Type: Function

Prescribes how the value originally produced by parsing is transformed, before being returned. See the JSON.parse docs for more.

Related


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Current Tags

  • 7.0.1                                ...           latest (4 years ago)

6 Versions

  • 7.0.1                                ...           4 years ago
  • 6.2.0                                ...           6 years ago
  • 2.0.0                                ...           9 years ago
  • 1.1.0                                ...           10 years ago
  • 4.0.0                                ...           8 years ago
  • 5.3.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org