Alexandro.Net

Version 1.0.0

@stackline/parse-json

Parse JSON with more helpful errors

Independent maintenance of parse-json 6.0.2. Original authors and licenses are retained.

Installation

# Preserve existing imports with an npm alias
npm install parse-json@npm:@stackline/parse-json@1.0.0
# Or use the scoped package name in your imports
npm install @stackline/parse-json@1.0.0

Node.js: ^12.20.0 || ^14.13.1 || >=16.0.0. Read the compatibility and maintenance notes before migrating.

Usage and API

The reference below may retain upstream package names. Use the alias installation above to run those imports with this Stackline release.

parse-json

Parse JSON with more helpful errors

Install

npm install parse-json

Usage

import parseJson from 'parse-json';

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


JSON.parse(json);
/*
undefined:3
}
^
SyntaxError: Unexpected token }
*/


parseJson(json);
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}'

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


parseJson(json, 'foo.json');
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


// You can also add the filename at a later point
try {
    parseJson(json);
} catch (error) {
    if (error instanceof parseJson.JSONError) {
        error.fileName = 'foo.json';
    }

    throw error;
}
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/

API

parseJson(string, reviver?, filename?)

Throws a JSONError when there is a parsing error.

string

Type: string

reviver

Type: Function

Prescribes how the value originally produced by parsing is transformed, before being returned. See JSON.parse docs for more.

filename

Type: string

The filename displayed in the error message.

parseJson.JSONError

Exposed for instanceof checking.

fileName

Type: string

The filename displayed in the error message.

codeFrame

Type: string

The printable section of the JSON which produces the error.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Upstream issues and maintenance review

Upstream origin and triage

Reviewed issues

Primary-source snapshot: 2026-09-29T00:22:11.014065+00:00. Most recently updated 100 open and 30 closed issue/PR entries; PRs removed. This is triage evidence, not a claim of exhaustive review.

Maintenance adoption with preserved runtime payload. No runtime defect correction is claimed. Reports remain visible for subsequent targeted reproduction.

The structured snapshot in .stackline/issue-triage.json also records recently closed reports. Issues for unrelated packages in shared monorepositories were qualified as outside this fork’s runtime scope. No maintainer was contacted.

Release files and references

Package bytes, npm provenance and the immutable GitHub release were verified for this version. Security checks describe the reviewed release; documented compatibility risks and upstream reports are not blanket claims of resolution.