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

parse-json 5.2.0

Parse JSON with more helpful errors
Package summary
Share
0
issues
2
licenses
16
MIT
1
ISC
Package created
28 Jul 2015
Version published
18 Jan 2021
Maintainers
1
Total deps
17
Direct deps
4
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
16 Packages, Including:
@babel/code-frame@7.24.2
@babel/helper-validator-identifier@7.22.20
@babel/highlight@7.24.2
ansi-styles@3.2.1
chalk@2.4.2
color-convert@1.9.3
color-name@1.1.3
error-ex@1.3.2
escape-string-regexp@1.0.5
has-flag@3.0.0
is-arrayish@0.2.1
js-tokens@4.0.0
json-parse-even-better-errors@2.3.1
lines-and-columns@1.2.4
parse-json@5.2.0
supports-color@5.5.0

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:
picocolors@1.0.0
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

4
All Dependencies CSV
β“˜ This is a list of parse-json 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
@babel/code-frame7.24.223.55 kBMIT
prod
error-ex1.3.23.47 kBMIT
prod
json-parse-even-better-errors2.3.14.45 kBMIT
prod
lines-and-columns1.2.42.22 kBMIT
prod

Visualizations

Frequently Asked Questions

What does parse-json do?

The "parse-json" library is an npm package designed to parse JSON data with more user-friendly and informative error messages. Instead of returning a generic error, parse-json provides a detailed error stack which byte-position of the invalid syntax, helping developers to quickly and precisely pinpoint issues in their JSON data. This enhanced level of detail can greatly reduce debugging time and improve coder efficiency.

How do you use parse-json?

To use parse-json in JavaScript, you first need to install the package to your project using npm. In your terminal, run the command npm install parse-json. Once installed, import the parse-json function, along with JSONError for error handling, into your script.

Given a JSON string 'json', you can parse it with parse-json as follows.

import parseJson, {JSONError} from 'parse-json';

const json = '{\n\t"foo": true,\n}';

// Use parseJson instead of JSON.parse()
parseJson(json);

To connect a JSON error with a specific file, you can either pass the filename as an argument in the parse-json call, or attach it to the error instance later, like this:

// Passing filename as an argument
parseJson(json, 'foo.json');

// Attaching filename to the error later
try {
    parseJson(json);
} catch (error) {
    if (error instanceof JSONError) {
        error.fileName = 'foo.json';
    }
    throw error;
}

This usage of parse-json enhances error tracing and can make debugging a more targeted process.

Where are the parse-json docs?

Detailed documentation for the parse-json package is available within the readme file at the project's GitHub page: https://github.com/sindresorhus/parse-json. The readme covers installation, usage, and API. For more specific information about the JSON.parse() function and the use of the reviver callback, you can refer to the Mozilla Developer Network documentation linked in the Parse-JSON documentation.