Skip to content

Instantly share code, notes, and snippets.

@etoxin
Created November 30, 2016 23:05
Show Gist options
  • Select an option

  • Save etoxin/656d65308621eee8ae7afb1cb4831d5a to your computer and use it in GitHub Desktop.

Select an option

Save etoxin/656d65308621eee8ae7afb1cb4831d5a to your computer and use it in GitHub Desktop.
JSON Parse
/**
* Lodash JSON Parse with error handling.
* The _.attempt prevents JSON.parse from throwing an application error. Instead, it return an Error object.
* @requires _
* @param str
* @returns {*}
*/
function lodashJSONParse (str) {
return _.attempt(JSON.parse.bind(null, str));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment