StoicBuilder

HandbookI the LudusNested data

Ithe Ludus, Read code

Nested data

1 min readUpdated 28 November

In plain words

Nested data is objects and arrays stored inside each other, like an order holding a list of items that each hold their own details.

Where you see it

A QuickBite order from the API holds a restaurant object, an items array and a delivery object with an address inside it. To reach the city, the code walks down each layer: order.delivery.address.city.

src/pages/OrderPage.tsxbrowser
const order = { restaurant: { name: "Lotus Kitchen" }, items: [{ name: "Spring rolls", quantity: 2 }], delivery: { address: { city: "Lisbon" } },}; order.items[0].name; // "Spring rolls"order.delivery.address.city; // "Lisbon"
Each dot or bracket goes one layer deeper.

What goes wrong

  1. One missing layer crashes the page

    Pickup orders have no delivery object, so order.delivery.address throws "Cannot read properties of undefined". Optional chaining, order.delivery?.address, returns undefined instead.

  2. Guessing the shape instead of checking it

    The agent assumes the items sit at the top level when the API puts them one layer down. Log one real response and read it before writing code against it.

  3. Copying the outer layer, editing an inner one

    { ...order } copies only the top layer. Change copy.delivery.address and the original order changes with it.

    const copy = { ...order }; copy.delivery.address.city = "Porto";

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Log one real response from this API, show me its full shape with every nested key, then write the code against that shape. Use optional chaining wherever a layer can be missing, and list the layers that can be.

Quick check

Sign in to earn +10 XP for it

A pickup order crashes QuickBite's order page with "Cannot read properties of undefined (reading 'address')". What's missing?

Got a prompt that touches nested data?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.