catch-json-parse
v0.0.2
Published
JSON.parse in a try-catch with error handler
Downloads
4
Readme
catch-json-parse
#####JSON.parse in a try-catch with error handler
####Why?
I wanted to:
- get rid of the try catch block in my code
- be able to still use the catch as an error handler
--
parseJson= require( 'catch-json-parse' );
var json= JSON.stringify();
var errHandler= function( err ){
console.log( err );
// [SyntaxError: Unexpected token u]
};
var obj= parseJSON( json, errHandler ) || {};
console.log( obj );
// {}
###license
MIT