Reading a Full JSON Payload
A JSON object is a single structured thing; an array is a list of things. Most real payloads are just objects containing arrays of objects.
order.json
- Starts with
{ β¦ }β top-level object; order_idβ string;customerβ nested object withemail;line_itemsβ array[ ... ]of objects (each line item);currencyβ string;paidβ boolean.
What the Payload Actually Describes
The object encodes an order: who (customer), what (line_items), money (currency), and status (paid). Totals aren't stored, they're derived. With a consistent shape, any node (or tiny code step) can compute them later. Before handing anything to AI, spell out the exact calculation you want. This prevents guessing, keeps outputs predictable, and makes the result easy to validate.
AI prompt:
Tiny Helpers
Sometimes you don't need a full function, a short expression or a few lines of code can handle totals or counts right inside your workflow. Use this to count how many line_items exist.
{{$json["line_items"] ? $json["line_items"].length : 0}}
If you need to calculate totals, a quick reduce loop inside a Code node does the trick.
const items = $json.line_items ?? [];
const subtotal = items.reduce((s, it) => s +
(Number(it.qty) || 0) * (Number(it.price) || 0), 0);
return [{ json: { subtotal: Number(subtotal.toFixed(2)) } }];
If upstream accidentally sends "19.99" as a string, cast with Number(...) before math.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.17
Reading a Full JSON Payload
Swipe to show menu
A JSON object is a single structured thing; an array is a list of things. Most real payloads are just objects containing arrays of objects.
order.json
- Starts with
{ β¦ }β top-level object; order_idβ string;customerβ nested object withemail;line_itemsβ array[ ... ]of objects (each line item);currencyβ string;paidβ boolean.
What the Payload Actually Describes
The object encodes an order: who (customer), what (line_items), money (currency), and status (paid). Totals aren't stored, they're derived. With a consistent shape, any node (or tiny code step) can compute them later. Before handing anything to AI, spell out the exact calculation you want. This prevents guessing, keeps outputs predictable, and makes the result easy to validate.
AI prompt:
Tiny Helpers
Sometimes you don't need a full function, a short expression or a few lines of code can handle totals or counts right inside your workflow. Use this to count how many line_items exist.
{{$json["line_items"] ? $json["line_items"].length : 0}}
If you need to calculate totals, a quick reduce loop inside a Code node does the trick.
const items = $json.line_items ?? [];
const subtotal = items.reduce((s, it) => s +
(Number(it.qty) || 0) * (Number(it.price) || 0), 0);
return [{ json: { subtotal: Number(subtotal.toFixed(2)) } }];
If upstream accidentally sends "19.99" as a string, cast with Number(...) before math.
Thanks for your feedback!