0.1.6 • Published 6 years ago

better-error-message-for-json-parse v0.1.6

Weekly downloads
102
License
MIT
Repository
github
Last release
6 years ago

Safe JSON Parse

The main goal of this project is to provide a nice error message for the SyntaxError that may occur while parsing JSON data.

For example, parsing the following JSON:

{
  "index": 1,
  "index_start_at": 56,
  "integer": 6,
  "float": 11.6816,
  "name": "Eva",
  "surname" "Rowland",
  "fullname": "Denise Pickett",
  "email": "jack@garrison.vc",
  "bool": false
}

will result in the following error message:

Unexpected string in JSON at position 105
  "name": "Eva",
  "surname" "Rowland",
-----------^
  "fullname": "Denise Pickett"

How to use

  1. import it
var { safeJsonParse } = require('better-error-message-for-json-parse');
  1. use it
try {
  safeJsonParse('{"a": 2, "b": 3, "v" 3, "e": 4 }');
} catch (e) {
  console.log(e);
}
  1. enjoy:
$ node index.js
SyntaxError: Unexpected number in JSON at position 21
{"a": 2, "b": 3, "v" 3, "e": 4 }
--------------------^
at exports.safeJsonParse
0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago