try-json-parse

Doesn't throw an error when JSON.parse() fails, just returns undefined

Just like JSON.parse(), except it returns instead of throwing an error for invalid JSON.

var JSONparse = require('./index'),
    assert    = require('assert'),
    fs        = require('fs');
 
fs.readFile(__dirname + '/package.json', function(errcontent) {
  var pkgJson;
 
  if (err) { throw err; }
 
  pkgJson = JSONparse(content);
  assert.equal(pkgJson.name, 'try-json-parse');
  assert(JSONparse(fs.readFileSync(__filename)) === );
});

Got tired of writing try {} catch {}.

MIT