You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lite-json-parse

Lightweight JSON parse errback function

0.0.2
latest
Version published
Weekly downloads
4
300%
Maintainers
1
Weekly downloads
 
Created

lite-json-parse

Lightweight JSON parse errback function

Reduce the boilerplate of wrapping every JSON.parse in a try/catch block. This no frills nanolibrary will safely parse JSON and return a javascript object or an error object in a node-style error-first callback function.

Use in node or in the browser.

Example

var parseJSON = require('lite-json-parse');
var json = "{\"food\":\"pizza\",\"drinks\":[\"soda\",\"red pop\",\"root beer\"]}";

parseJSON(json, function (err, pizzaParty) {
  if (err) {
    // handle parse error object
    return console.log(err);
  }

  // success - have a pizza party!
  pizzaParty.drinks.forEach(function(beverage) {
    console.log(beverage);
  });
});

:floppy_disk:

FAQs

Package last updated on 10 Mar 2016

Did you know?

Socket

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