Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@expo/json-file
Advanced tools
A module for reading, writing, and manipulating JSON files
The @expo/json-file npm package is a utility library for reading and writing JSON files. It provides a simple and convenient API for these operations, handling various edge cases and providing helpful error messages.
Read JSON file
This feature allows you to read a JSON file asynchronously and parse its contents into a JavaScript object.
{"const { readAsync } = require('@expo/json-file');
async function readJsonFile(filePath) {
const json = await readAsync(filePath);
return json;
}
readJsonFile('path/to/file.json').then(data => console.log(data));"}
Write JSON file
This feature enables you to write a JavaScript object to a file as JSON asynchronously, with options to format the output.
{"const { writeAsync } = require('@expo/json-file');
async function writeJsonFile(filePath, data) {
await writeAsync(filePath, data);
}
const data = { key: 'value' };
writeJsonFile('path/to/file.json', data);"}
Modify JSON file
This feature allows you to modify an existing JSON file by providing an object with the modifications you want to apply.
{"const { modifyAsync } = require('@expo/json-file');
async function modifyJsonFile(filePath, modifications) {
await modifyAsync(filePath, modifications);
}
modifyJsonFile('path/to/file.json', { key: 'newValue' });"}
The 'jsonfile' package offers similar functionality to '@expo/json-file' for reading and writing JSON files. It provides methods like 'readFileSync', 'writeFileSync', 'readFile', and 'writeFile'. The main difference is that 'jsonfile' does not provide modification capabilities directly, and it has both synchronous and asynchronous methods.
While 'fs-extra' is a more general file system utility library, it includes methods for reading and writing JSON files, such as 'readJson', 'writeJson', 'readJsonSync', and 'writeJsonSync'. It extends the built-in 'fs' module in Node.js and provides additional file operation methods. It is more comprehensive but less specialized than '@expo/json-file'.
@expo/json-file
A library for reading and writing JSON files.
Install @expo/json-file
in your project.
yarn add @expo/json-file
import JsonFile, { JSONObject } from '@expo/json-file';
// Create a file instance
const jsonFile = new JsonFile<JSONObject>(filePath);
// Interact with the file
await jsonFile.readAsync();
await jsonFile.writeAsync({ some: 'data' });
FAQs
A module for reading, writing, and manipulating JSON files
The npm package @expo/json-file receives a total of 1,197,460 weekly downloads. As such, @expo/json-file popularity was classified as popular.
We found that @expo/json-file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 28 open source maintainers 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.