Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 4, 2024 via pnpm

jsonfile 6.1.0

Easily read/write JSON files.
Package summary
Share
0
issues
2
licenses
2
MIT
1
ISC
Package created
10 Sep 2012
Version published
31 Oct 2020
Maintainers
2
Total deps
3
Direct deps
2
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
2 Packages, Including:
jsonfile@6.1.0
universalify@2.0.1

ISC License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
graceful-fs@4.2.11
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

2
All Dependencies CSV
β“˜ This is a list of jsonfile 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
graceful-fs4.2.119.57 kBISC
prod optional
universalify2.0.12.02 kBMIT
prod

Visualizations

Frequently Asked Questions

What does jsonfile do?

Jsonfile is a lightweight, non-browser compatible Node.js module that simplifies the operations of reading and writing JSON files. It eliminates the need to manually write JSON.stringify() and fs.writeFile(), or JSON.parse() with fs.readFile() enclosed in try/catch blocks, drastically increasing coding efficiency.

How do you use jsonfile?

To harness jsonfile in your project, first, install the module by using npm install command as below:

npm install --save jsonfile

Using jsonfile is quite straightforward. Here are several common use-case code snippets:

Reading a JSON file asynchronously

const jsonfile = require('jsonfile')

const file = '/tmp/data.json'

jsonfile.readFile(file, function (err, obj) {
  if (err) console.error(err)
  console.dir(obj)
})

Writing to a JSON file asynchronously

const jsonfile = require('jsonfile')

const file = '/tmp/data.json'
const obj = { name: 'JP' }

jsonfile.writeFile(file, obj, function (err) {
  if (err) console.error(err)
})

What's compelling about jsonfile is that it supports both callback style and promise style. So, if you prefer using promises, you can rewrite the reading and writing operations like this:

Reading a JSON file with promises

const jsonfile = require('jsonfile')

const file = '/tmp/data.json'

jsonfile.readFile(file)
  .then(obj => console.dir(obj))
  .catch(error => console.error(error))

Writing to a JSON file with promises

const jsonfile = require('jsonfile')

const file = '/tmp/data.json'
const obj = { name: 'JP' }

jsonfile.writeFile(file, obj)
  .then(res => {
    console.log('Write complete')
  })
  .catch(error => console.error(error))

Where are the jsonfile docs?

The jsonfile documentation can be found in the readme file on the jsonfile GitHub repository. The readme file provides a comprehensive guide on how to use the module, showing various examples and explaining the parameters for each function. The repository's url is: git+ssh://git@github.com/jprichardson/node-jsonfile.git