safe-json-decode
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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"}'

Package Sidebar

Install

npm i safe-json-decode

Weekly Downloads

2

Version

1.0.6

License

MIT

Unpacked Size

13.4 kB

Total Files

11

Last publish

Collaborators

  • vinsjo