safe-json-parse-and-stringify
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

safe-json-parse-and-stringify

Install

npm i safe-json-parse-and-stringify --save

Usage

import { jsonParse ,jsonStringify } from 'safe-json-parse-and-stringify';

Detail

jsonParse(str, defaultValue)

use JSON.parse with try catch,if catch error, return defaultValue。

param

  • {any} str
  • {any} defaultValue

return {any}

demo

jsonParse('[1,2,3]', []);     // => {{JSON.stringify(jsonParse('[1,2,3]', []))}}
jsonParse([1,2,3], []);       // => {{JSON.stringify(jsonParse([1,2,3], []))}}
jsonParse('', []);            // => {{JSON.stringify(jsonParse('', []))}}

jsonParse('{a:1}', {});       // => {{JSON.stringify(jsonParse('{a:1}', {}))}}
jsonParse({a:1}, {});         // => {{JSON.stringify(jsonParse({a:1}, {}))}}

jsonStringify

see more at https://github.com/moll/json-stringify-safe

cloneDeep

see more at https://www.lodashjs.com/docs/lodash.cloneDeep

Readme

Keywords

none

Package Sidebar

Install

npm i safe-json-parse-and-stringify

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

6.66 kB

Total Files

12

Last publish

Collaborators

  • richiechoo1993