Skip to content

Latest commit

 

History

History
50 lines (28 loc) · 847 Bytes

README.md

File metadata and controls

50 lines (28 loc) · 847 Bytes

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