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 Mar 31, 2024 via pnpm

json-parse-even-better-errors 2.3.1

JSON.parse with context information on error
Package summary
Share
0
issues
1
license
1
MIT
Package created
27 Sep 2019
Version published
2 Sep 2020
Maintainers
6
Total deps
1
Direct deps
0
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
1 Packages, Including:
json-parse-even-better-errors@2.3.1
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

0
All Dependencies CSV
β“˜ This is a list of json-parse-even-better-errors 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does json-parse-even-better-errors do?

The npm package "json-parse-even-better-errors" is a Node.js library that improves the functionality of JSON.parse(). It provides more informative and easier to understand error messages which include the context and location of parse errors. It also takes care to preserve the newline and indentation styles present in the JSON data. These styles are kept in the object or array in Symbol.for('indent') and Symbol.for('newline') properties. This package can be particularly useful for developers who work with JSON data frequently and need a better way to handle and decipher errors.

How do you use json-parse-even-better-errors?

Here's how you can start using json-parse-even-better-errors. First, you need to install the package:

$ npm install --save json-parse-even-better-errors

Then, you can require it in your code like so:

const parseJson = require('json-parse-even-better-errors')

You can use it to parse JSON in a way similar to the JSON.parse() method, but with better errors:

parseJson('"foo"') // returns the string 'foo'
parseJson('garbage') // this will throw a more informative error message 

The package also provides a noExceptions method that returns undefined instead of throwing an error :

parseJson.noExceptions('garbage') // returns undefined

If you want to preserve JSON data indentation and newline character(s) when saving the file back to disk, you could use the following code:

const txt = await readFile('./package.json', 'utf8')
const data = parseJsonEvenBetterErrors(txt)
const indent = Symbol.for('indent')
const newline = Symbol.for('newline')
// .. do some stuff to the data ..
const string = JSON.stringify(data, null, data[indent]) + '\n'
const eolFixed = data[newline] === '\n' ? string
  : string.replace(/\n/g, data[newline])
await writeFile('./package.json', eolFixed)

Where are the json-parse-even-better-errors docs?

The documentation for json-parse-even-better-errors can be found in its GitHub repository. The readme file in the repository provides a detailed explanation of the package, including installation instructions, features, example usage, and API documentation.