json-parse-default
v1.1.0
Published
Parse JSON with default value
Downloads
47
Maintainers
Readme
json-parse-default
Parse JSON with default value
Install
$ npm install json-parse-default
Usage
const jsonParse = require('json-prase-default');
const json = '{"enable": true}';
const jsonObj = jsonParse(json, null, {}, null);
const jsonObj = jsonParse(json, null, {}, (e) => console.log(e));
API
jsonParse(string, reviver?, default?, onError?)
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.
default
Type: object
When there is exception, this value will be return
onError
Type: Function
error callback function