Updated JSON parser to be more robust