More functional style. Added a try catch around the JSON.parse