Added minor error handling to json_generator.