Fix “.map is not a function” in n8n expressions
What this error means
.map(), .filter() and .join() only exist on arrays. The error means the value you called it on is something else — usually a string that looks like an array, a single object, or nothing at all.
Common causes
- The array arrives as a JSON string (
"[\"a\",\"b\"]"), common with form tools, Google Sheets cells and some APIs. - A single value comes back as an object when there is one result, and as an array only when there are several.
- The field is empty or missing for some items.
- You expected n8n to give you a list, but the previous node already split it into separate items.
How to fix it
- Check the type in the input panel: arrays show as a list with an index, strings show in quotes.
- If it's a JSON string, parse it first:
JSON.parse($json.tags). - If it's sometimes one object, wrap it:
[].concat($json.tags ?? [])always gives you an array. - If the previous node outputs one item per element, you don't need
.map()at all — use$json.fielddirectly, or Aggregate the items first.
❌ Breaks
{{ $json.tags.map(t => t.toUpperCase()) }}✅ Works
{{ JSON.parse($json.tags).map(t => t.toUpperCase()) }}💡 Pro tip: Array.isArray(value) returns true only for real arrays — use it in an IF node when the shape of your data varies between runs.
🧪 Fix it yourself
A form tool sends the selected tags as a JSON string, so .map() fails. Parse the string and return the tags in uppercase.
{
"tags": "[\"vip\", \"dubai\"]"
}
⚙️ Your fix is executed against both test items — any correct solution passes.
✅ Solution
Output: ["VIP", "DUBAI"]