Parse your json safely and stop writing try {} catch {}
npm install json-parse-safeParse your json safely and stop writing try {} catch {}
!Code Coverage 100%
##### reviver (optional)
* if a function, prescribes how the value originally produced by parsing is transformed, before being returned, more info about this param in here
{value, error} `` js
var JSONParse = require('json-parse-safe');
var str = '{"cat": "Peter", "age": 1, "colors": ["white", "cyan", "black"]}';
var obj = JSONParse(str);
// obj.value should be
{
cat: 'Peter',
age: 1,
colors: ['white', 'cyan', 'black']
}
`
getting the exception
` js
var bad = '{"cat": "Peter" "age": 1}';
var obj = JSONParse(str);
// obj.value should be 'undefined'
// obj.error should be an Error
console.log(obj.error);
console.log(obj.error.message);
console.log(obj.error.stack);
`
##### This project has been set up with a precommit that forces you to follow a code style, no jshint issues and 100% of code coverage before commit
to run test
` js`
npm test
to run jshint
` js`
npm run jshint
to run code style
` js`
npm run code-style
to run check code coverage
` js`
npm run check-coverage
to open the code coverage report
` js``
npm run open-coverage