tjp

try-json-parse

Just like JSON.parse(), except that it doesn't throw an error for invalid JSON, it just returns null

Showing:

Popularity

Downloads/wk

7.6K

GitHub Stars

9

Maintenance

Last Commit

4yrs ago

Contributors

6

Package

Dependencies

0

Size (min+gzip)

0.2KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100