Added error checking for invalid json.