Skip to documentation

package

@stackline/parse-json 1.0.4 — installation and API

Parse JSON with more helpful errors

Install @stackline/parse-json

npm install @stackline/[email protected]

Package version: 1.0.4. Metadata verified: 2026-11-12. This is separate from the framework version and demonstration runtime.

Node.js requirement
{"node": "^12.20.0 || ^14.13.1 || >=16.0.0"}
Accepted peer dependencies (declared ranges)
{}

Tested environments are described in the versioned README and linked source checks. A declared peer range is not evidence that every version in it was tested.

Versioned reference

This reference comes from the published @stackline/[email protected] README. Its upstream attribution and license remain with the source. Benchmark and security statements describe the cited tests and advisories, not a guarantee for every application.

@stackline/parse-json

Parse JSON with more helpful errors.

Documentation | npm | Issues | Repository

Current package version: 1.0.4


Why this package?

@stackline/parse-json is the Stackline-maintained distribution of [email protected]. It is an independent continuation of parse-json; original authors and licenses remain credited below.

Compatibility

Item Value
Package @stackline/[email protected]
API target [email protected]
Supported Node.js ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0
License MIT
Module type module
Runtime dependencies @babel/code-frame, error-ex, json-parse-even-better-errors, lines-and-columns

Installation

npm install @stackline/parse-json

Preserve existing imports and plugin resolution with an npm alias:

npm install parse-json@npm:@stackline/parse-json

Usage and API reference

Parse JSON with more helpful errors

Install

npm install @stackline/parse-json

Usage

import parseJson from '@stackline/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.

Credits and original authors

Original copyright, license notices and contributor acknowledgements remain part of this distribution. Stackline maintenance does not replace authorship of the original work.

License

MIT. See the license and notice files in the repository.

Use this repository's issue tracker for reproducible bugs and feature requests. Join r/Stackline for examples, usage questions and release discussions.

Upstream documentation

The original upstream README is preserved in README.upstream.md.