
Research
/Security News
Fake imToken Chrome Extension Steals Seed Phrases via Phishing Redirects
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.
parse-json
Advanced tools
Parse JSON with more helpful errors
npm install parse-json
import parseJson, {JSONError} from 'parse-json';
const json = '{\n\t"foo": true,\n}';
JSON.parse(json);
/*
SyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)
*/
parseJson(json);
/*
JSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)
1 | {
2 | "foo": true,
> 3 | }
| ^
*/
parseJson(json, 'foo.json');
/*
JSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1) in foo.json
1 | {
2 | "foo": true,
> 3 | }
| ^
fileName: 'foo.json',
[cause]: SyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)
at JSON.parse (<anonymous>)
at ...
*/
// You can also add the filename at a later point
try {
parseJson(json);
} catch (error) {
if (error instanceof JSONError) {
error.fileName = 'foo.json';
}
throw error;
}
/*
JSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1) in foo.json
1 | {
2 | "foo": true,
> 3 | }
| ^
fileName: 'foo.json',
[cause]: SyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)
at JSON.parse (<anonymous>)
at ...
*/
Throws a JSONError when there is a parsing error.
Type: string
Type: Function
Prescribes how the value originally produced by parsing is transformed, before being returned. See JSON.parse docs for more.
Type: string
The filename displayed in the error message.
Exposed for instanceof checking.
Type: string
The filename displayed in the error message.
Type: string
The printable section of the JSON which produces the error.
Type: string
The raw version of codeFrame without colors.
json5 is a JSON parser and serializer that allows for comments, trailing commas, and other non-standard features. It is similar to parse-json but aims to be a superset of the JSON5 data format, which extends the JSON format to include additional JavaScript features.
json-parse-better-errors is another JSON parsing library that provides more helpful error messages than the native JSON.parse. It is similar to parse-json in its goal to improve error feedback but does not support comments or trailing commas.
json-parse-safe is a safe JSON parser that returns an error instead of throwing one. This can be useful for applications that need to handle JSON parsing errors more gracefully. It does not provide the extended syntax support that parse-json does.
FAQs
Parse JSON with more helpful errors
The npm package parse-json receives a total of 80,005,686 weekly downloads. As such, parse-json popularity was classified as popular.
We found that parse-json demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.

Security News
Latio’s 2026 report recognizes Socket as a Supply Chain Innovator and highlights our work in 0-day malware detection, SCA, and auto-patching.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.