n8n Expressions Exercise: Prepare Updates Without Losing Valid Values
Practise n8n expressions with synthetic records: distinguish missing, null and empty fields, compare defaults, and prepare an explicit payload without live writes.

Checked against the cited sources on .
Your n8n expressions exercise
This editorial exercise uses n8n expressions to prepare an update payload while keeping missing fields, null, empty strings, zero and false distinct. Your task is to predict each output, inspect it in your own environment, and explain any differences. The suggested expressions and expected outputs below have not been executed or validated.
You need your own n8n Cloud or Self-hosted environment. n8n documents parameter-level expressions with computed-value previews on both. Use Edit Fields in JSON Output mode to supply one synthetic record at a time, followed by another Edit Fields node for mapping. No external API or credentials are needed.
Keep this exercise local: prepare output only. Live writes, HTTP serialization and destination-specific rules for omission, clearing and validation are outside its scope. We think separating payload preparation from delivery makes the field policy easier to reason about.
Sources: n8n-docs/docs/build/work-with-data/expressions-versus-data-nodes.md at main · n8n-io/n8n-docs · GitHub, n8n-docs/docs/integrations/builtin/core-nodes/n8n-nodes-base.set.md at main · n8n-io/n8n-docs · GitHub
Predict presence before choosing defaults

Create these separate inputs: {}, {"value":null}, {"value":""}, {"value":0}, {"value":false}, {"value":"Ada"}, {"value":[]}, and {"value":{}}. Add "unrelated":"drop-me" to each record. First predict whether value exists, then evaluate {{ Object.prototype.hasOwnProperty.call($json, 'value') }}. MDN distinguishes an own property's presence from its value, including null or undefined.
Compare {{ $json.value ?? 'DEFAULT' }} with {{ $ifEmpty($json.value, 'DEFAULT') }}. MDN documents that ?? defaults for null and undefined; n8n documents a broader empty-value policy for $ifEmpty(). This n8n expressions cheat sheet gives editorial predictions for comparison with your output.
| Input value | Own key? | With ?? | With $ifEmpty() |
|---|---|---|---|
| Absent | false | DEFAULT | DEFAULT |
| null | true | DEFAULT | DEFAULT |
| Empty string | true | Empty string | DEFAULT |
| 0 | true | 0 | 0 |
| false | true | false | false |
| Ada | true | Ada | Ada |
| [] | true | [] | DEFAULT |
| {} | true | {} | DEFAULT |
Sources: n8n-docs/docs/build/work-with-data/transform-data/expression-reference/root.md at main · n8n-io/n8n-docs · GitHub, Nullish coalescing operator (??) - JavaScript | MDN, Object.prototype.hasOwnProperty() - JavaScript | MDN
Build an allowlisted update payload

For this exercise, use a different policy for updates: omit an absent value, retain an explicit null, and preserve every other supplied value and its type. Allow only the value key into the payload. These are editorial requirements, not a real destination's contract. In our view, defaults and update inclusion deserve separate decisions because they answer different questions.
Suggested payload expression: {{ { ...(Object.prototype.hasOwnProperty.call($json, 'value') ? { value: $json.value } : {}) } }}. MDN documents that spreading an empty object omits the property, while assigning undefined leaves a property present. That distinction concerns JavaScript objects.
Follow this suggested sequence in the mapping node. n8n documents expressions in Edit Fields JSON Output and controls for excluding unmapped input; control labels may differ across installations.
- Select JSON Output mode and enter the suggested payload expression.
- Configure output inclusion to exclude the original input fields.
- Inspect the computed preview, then execute the local mapping node.
- Compare key presence, value and type against your written prediction for each record.
Sources: n8n-docs/docs/integrations/builtin/core-nodes/n8n-nodes-base.set.md at main · n8n-io/n8n-docs · GitHub, Object.prototype.hasOwnProperty() - JavaScript | MDN, Spread syntax (...) - JavaScript | MDN
Troubleshoot defaults and conditional expressions
If zero or false becomes DEFAULT, check whether you used ||. MDN documents that || falls back for any falsy value, whereas ?? preserves values other than null and undefined. If empty arrays or objects become DEFAULT, compare that result with n8n's documented $ifEmpty() policy.
For n8n expressions, if a condition controls whether a key exists, inspect the resulting object's keys as well as its displayed value. Presence checks and conditional object construction address that requirement; a truthiness check alone cannot distinguish all the supplied cases.
For an optional nested-access extension, Suyash Raj's vendor tutorial illustrates the pattern {{ $json.address?.city ?? 'Unknown' }}. Treat it as a suggested extension. If logic fails after moving into a Code node, n8n documents that top-level transformation helpers such as $if() are available only in the expressions editor.
Sources: n8n-docs/docs/build/work-with-data/transform-data/expression-reference/root.md at main · n8n-io/n8n-docs · GitHub, Nullish coalescing operator (??) - JavaScript | MDN, n8n Expressions and JavaScript in Workflows, Object.prototype.hasOwnProperty() - JavaScript | MDN, Spread syntax (...) - JavaScript | MDN, n8n-docs/docs/build/code-in-n8n/use-built-in-shortcuts.md at main · n8n-io/n8n-docs · GitHub
Completion criteria and reflection
Finish by recording predicted and observed outputs separately. Use this editorial checklist to decide whether your proposed mapping meets the exercise requirements.
Suggested reflection: why would replacing an absent field with DEFAULT be different from omitting it? Explain which expression chooses a fallback value and which decides whether to include a property. Before adapting the result to a real integration, replace the exercise policy with that destination's documented contract.
Sources: Nullish coalescing operator (??) - JavaScript | MDN, Object.prototype.hasOwnProperty() - JavaScript | MDN, Spread syntax (...) - JavaScript | MDN


