← Back to blog

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.

A learner sorts distinct field-value objects into a parcel to practise n8n expressions for update preparation.

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

Two trays contrast narrow and broad fallback policies for the exercise's empty and falsy field values.
The paired trays illustrate how different fallback policies can preserve or replace different kinds of values.

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.

Predicted results for the synthetic value field
Input valueOwn key?With ??With $ifEmpty()
AbsentfalseDEFAULTDEFAULT
nulltrueDEFAULTDEFAULT
Empty stringtrueEmpty stringDEFAULT
0true00
falsetruefalsefalse
AdatrueAdaAda
[]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

A hand selects one allowed field object and leaves unrelated input outside the prepared update parcel.
The selection sequence illustrates preparing an allowlisted payload while excluding unrelated input.

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.

  1. Select JSON Output mode and enter the suggested payload expression.
  2. Configure output inclusion to exclude the original input fields.
  3. Inspect the computed preview, then execute the local mapping node.
  4. 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

Put this into practice

Hands-on n8n challenges

Pick a challenge and build a working workflow in your own n8n environment, with five progressive tips per challenge.

Try a hands-on challenge

For your team

Custom n8n training programs for one team or department, run on your own n8n instance with your own tools and data.

Training for your team

n8n skills assessment

A free quiz of about 20 minutes: 30 questions in 10 skill areas and a level from Beginner to Expert. On AI Adoption Score, another project by the author of this site.

Get your n8n level