function parseJson(str) { try { return JSON.parse(str); } catch (err) { if (err instanceof SyntaxError) { return undefined; } else { throw err; } } }