1. read-json-sync
Read and parse a JSON file synchronously
read-json-sync
Package: read-json-sync
Created by: shinnn
Last modified: Sun, 26 Jun 2022 09:13:48 GMT
Version: 2.0.1
License: ISC
Downloads: 107,331
Repository: https://github.com/shinnn/read-json-sync

Install

npm install read-json-sync
yarn add read-json-sync

read-json-sync

npm version
Build Status
Coverage Status

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

 const readJsonSync = require('read-json-sync');

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.

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.

 // with-bom.json: '\uFEFF{"a": 1}'

JSON.parse('\uFEFF{"a": 1}'); // throws a SyntaxError

readJsonSync('with-bom.json'); //=> {a: 1}

License

ISC License © 2017 - 2018 Shinnosuke Watanabe

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin