Socket
Socket
Sign inDemoInstall

json-parse-better-errors

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-parse-better-errors

JSON.parse with context information on error


Version published
Weekly downloads
15M
increased by3.11%
Maintainers
1
Install size
7.59 kB
Created
Weekly downloads
 

Package description

What is json-parse-better-errors?

The json-parse-better-errors package is designed to provide more informative error messages when parsing JSON strings in JavaScript. This can be particularly useful in development environments where understanding the source of a JSON parsing error quickly is crucial. It wraps the standard JSON.parse method to catch errors and rethrow them with enhanced messages, indicating the exact position and nature of the syntax issue.

What are json-parse-better-errors's main functionalities?

Enhanced JSON parsing error messages

This feature enhances the error messages returned by the JSON.parse method. In the code sample, an attempt is made to parse an invalid JSON string. The json-parse-better-errors package catches the syntax error and provides a more informative error message, including the position of the error within the string.

"use strict";
const parseJson = require('json-parse-better-errors');
try {
  const obj = parseJson('{"foo": 1,}');
} catch (e) {
  console.error(e.message);
}

Other packages similar to json-parse-better-errors

Readme

Source

json-parse-better-errors npm version license Travis AppVeyor Coverage Status

json-parse-better-errors is a Node.js library for getting nicer errors out of JSON.parse(), including context and position of the parse errors.

Install

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

Table of Contents

Example

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

parseJson('"foo"')
parseJson('garbage') // more useful error message

Features

  • Like JSON.parse, but the errors are better.

Contributing

The npm team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The Contributor Guide has all the information you need for everything from reporting bugs to contributing entire new features. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.

All participants and maintainers in this project are expected to follow Code of Conduct, and just generally be excellent to each other.

Please refer to the Changelog for project history details, too.

Happy hacking!

API

> parse(txt, ?reviver, ?context=20)

Works just like JSON.parse, but will include a bit more information when an error happens.

Keywords

FAQs

Last updated on 30 Mar 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc