read-json-sync
A Node.js module to read and parse a JSON file synchronously
const readJsonSync = require('read-json-sync');
readJsonSync('package.json');
Node.js built-in require
and import
can do almost the same thing, but this module doesn't cache results.
Installation
Use npm.
npm install read-json-sync
API
const readJsonSync = require('read-json-sync');
readJsonSync(path [, options])
path: string
Buffer
URL
(JSON filename) or integer
(file descriptor)
options: Object
string
(fs.readFile
options or an encoding of the file)
Return: any
(parsed JSON data)
It automatically ignores the leading byte order mark.
JSON.parse('\uFEFF{"a": 1}');
readJsonSync('with-bom.json');
License
Creative Commons Zero v1.0 Universal