read-json-sync
A Node.js module to read and parse a JSON file synchronously
const readJsonSync = ; ; //=> {name: 'read-json-sync', version: '1.0.0', ...}
Node.js built-in require
and import
can do almost the same thing, but this module doesn't cache results.
Installation
npm install read-json-sync
API
const readJsonSync = ;
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.
// with-bom.json: '\uFEFF{"a": 1}' JSON; // throws a SyntaxError ; //=> {a: 1}
License
ISC License © 2017 - 2018 Shinnosuke Watanabe