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.
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 4.17
Reading a Full JSON Payload
Svep för att visa menyn
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.
Tack för dina kommentarer!