Your question is Flatten Nested Booking JSON With Python. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Airbnb internal workflows may receive booking metadata as nested JSON. Given a decoded payload from an Airbnb booking workflow, transform each booking into one flat record with normalized text, numeric prices, and stay totals.
payload["bookings"] and preserve input order."\$1,200.50" or " 30 " to Python floats.start_date and end_date. The nights are already in chronological order.cleaning or service fees as 0.0.booking_id, status, guest_name, guest_email, listing_id, city, start_date, end_date, nights, nightly_total, fees_total, and grand_total.The function receives a Python dictionary, not a JSON string. Do not use third-party libraries.
Input: payload, a dictionary containing a nonempty bookings list. Each booking contains the nested fields used below. Price values are strings, and each booking has at least one night.
Output: A list of flat dictionaries in the same order as the input bookings. Round no values; retain normal Python floating-point arithmetic.
def flatten_booking_payload(payload):