safe-json-decode
v1.0.6
Published
a minimal package for encoding and decoding json without unhandled exceptions being thrown on failure
Downloads
3
Readme
safe-json-decode
safe-json-decode
is a minimal package for encoding and decoding json without unhandled exceptions being thrown on failure
Package is bundled using microbundle
Installation
npm i safe-json-decode
In Node.js
// ESM:
import { decode, encode } from 'safe-json-decode';
// CommonJS:
const { decode, encode } = require('safe-json-decode');
// or:
const safeJSON = require('safe-json-decode');
Usage
decode('{"foo": "bar"}');
// => {foo: 'bar'}
decode('{invalidJson}');
// => null
encode({ foo: 'bar' });
// => '{"foo": "bar"}'