Added error handling in parsing JSON.