Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Just like JSON.parse(), except that it doesn't throw an error for invalid JSON, it just returns null
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
CHANGELOG.md
LICENSE
README.md
index.js
package.json
test.js

README.md

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

Something went wrong with that request. Please try again.