parse-json-safe
v0.0.1
Published
parse json without try catch
Downloads
6
Readme
parseJsonSafe
Features
- parse json without try catch。
- support default value;
- object value will be returned as it self;
Usage
import { parseJsonSafe } from "parse-json-safe";
// normal
const json = parseJsonSafe(`{ "a": 1 }`);
// { a: 1 }
// when catch error, output default value
const json = parseJsonSafe("err", { a: 0 });
// { a: 0 }
// support object type
const json = parseJsonSafe({ a: 1 });
// { a: 1 }