Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    try-json-parsepublic

    try-json-parse

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

    Usage

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

    Motivation

    Got tired of writing try {} catch {}.

    License

    MIT

    install

    npm i try-json-parse

    Downloadsweekly downloads

    12,912

    version

    1.0.0

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar