项目作者: shinnn

项目描述 :
Read and parse a JSON file synchronously
高级语言: JavaScript
项目地址: git://github.com/shinnn/read-json-sync.git
创建时间: 2014-10-09T13:58:12Z
项目社区:https://github.com/shinnn/read-json-sync

开源协议:ISC License

下载


read-json-sync

npm version
Build Status
Coverage Status

A Node.js module to read and parse a JSON file synchronously

  1. const readJsonSync = require('read-json-sync');
  2. readJsonSync('package.json'); //=> {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

Use npm.

  1. npm install read-json-sync

API

  1. 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.

  1. // with-bom.json: '\uFEFF{"a": 1}'
  2. JSON.parse('\uFEFF{"a": 1}'); // throws a SyntaxError
  3. readJsonSync('with-bom.json'); //=> {a: 1}

License

ISC License © 2017 - 2018 Shinnosuke Watanabe