Socket
Socket
Sign inDemoInstall

try-json-parse

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    try-json-parse

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


Version published
Weekly downloads
5.3K
decreased by-27.43%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 06 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc