JSON.parse with a try/catch
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
index.js
package.json
test.js

README.md

validJSON

Returns either a parsed {Object} or {Boolean} false.

Usage

Install from npm:

npm install validjson

Require and use:

var validjson = require('validjson');
var str = '{"ok": 2013}';
var obj = validjson(str);
if (obj) {
    console.log(obj);
}