tryjson
Version:
Try to parse a string as JSON and return undefined on failure
12 lines (8 loc) • 309 B
JavaScript
;
var tryjson = require('.');
console.log(tryjson.parse('{"a":1,"b":2}', {err: 'bad json'}));
console.log(tryjson.parse('{"a":1,"b":2', {err: 'bad json'}));
var x = {a: 1};
console.log(tryjson.stringify(x, {err: 'bad object'}));
x.b = x;
console.log(tryjson.stringify(x, {err: 'bad object'}));