to_json working with generators