Hotel guests from nested JSON

Hotel guests from nested JSON

You work at the SunTrail tour operator. A partner booking system sends every reservation as a JSONB payload: a guest object with the guest name, holding a nested contact object with city and email. The guest-care team needs a list of guests with their cities to send regional arrival guides. Some bookings arrive without the contact block — include those guests too, just without a city. Return columns: - booking_id — booking number (integer); - hotel — hotel name (a regular table column); - guest_name — the guest name from guest.name, as text; - guest_city — the city from guest.contact.city, as text; NULL when the contact or the city is absent. Sort by booking_id ascending. One row per booking, no filtering.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

booking_idhotelguest_nameguest_city
1Palm Bay ResortAlice RoyLyon
2Palm Bay ResortMarco DelucaTurin
3Cedar LodgeJane WuNULL
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid