parseJSON = (str, data) => {

  try {

    return JSON.parse(str);

  } catch (Error) {

    return data;

  }

}
Try to turn the string into a javascript object. If the
transformation fails, return the optionally provided `data` object.

@param {string} str - The string to parse.
@param {*} data - The default value if the operation fails.
@return {*} Either the object resulting from the parsing operation
    or `undefined` or `data` if the operation failed.