Parse JSON
parseJSON lets you parse a JSON value without a try/catch block. At the same time, you can add a default fallback value.
Parse JSON without try/catch
Just use parseJSON and save a few lines of code each time you want to try to parse a JSON value that might be invalid.
// Beforetry { const cookie = context.cookies.get('cookieName') const cookie = parseJSON(cookie)} catch (error) { console.error(error)}// Afterconst cookie = context.cookies.get('cookieName')const cookie = parseJSON(cookie)