Added a more sophisticated JSON parsing