Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
load-json-file
Advanced tools
The 'load-json-file' npm package is a utility that allows for easy reading and parsing of JSON files in Node.js. It simplifies the process of loading JSON data from files, handling potential errors, and converting the JSON string into a JavaScript object.
Load JSON file
This feature allows you to asynchronously load and parse a JSON file, returning a promise that resolves with the parsed JSON object.
const loadJsonFile = require('load-json-file');
loadJsonFile('foo.json').then(json => {
console.log(json);
}).catch(error => {
console.error('Error loading JSON file:', error);
});
Synchronous JSON file loading
This feature provides a synchronous method to load and parse a JSON file, useful when you need to load JSON data at the start of an application or in a synchronous script.
const loadJsonFile = require('load-json-file');
try {
const json = loadJsonFile.sync('foo.json');
console.log(json);
} catch (error) {
console.error('Error loading JSON file:', error);
}
Similar to 'load-json-file', 'jsonfile' offers APIs to read and write JSON files. It provides both asynchronous and synchronous methods but has additional write capabilities, making it more versatile if modification of JSON files is required.
While 'fs-extra' extends the native 'fs' module and includes all its methods, it also adds file operation methods not found in the standard library. It supports JSON file operations similar to 'load-json-file' but is more comprehensive in terms of general file handling capabilities.
Read and parse a JSON file
It also strips UTF-8 BOM.
$ npm install load-json-file
import {loadJsonFile} from 'load-json-file';
console.log(await loadJsonFile('foo.json'));
//=> {foo: true}
Returns a Promise<unknown>
with the parsed JSON.
Returns the parsed JSON.
Type: object
Type: Function
Applies a function to the JSON string before parsing.
Type: Function
Prescribes how the value originally produced by parsing is transformed, before being returned. See the JSON.parse
docs for more.
Available as part of the Tidelift Subscription.
The maintainers of load-json-file and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
FAQs
Read and parse a JSON file
The npm package load-json-file receives a total of 17,269,264 weekly downloads. As such, load-json-file popularity was classified as popular.
We found that load-json-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.