n8n error

Fix “.map is not a function” in n8n expressions

⚠️ $json.tags.map is not a function

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

  1. Check the type in the input panel: arrays show as a list with an index, strings show in quotes.
  2. If it's a JSON string, parse it first: JSON.parse($json.tags).
  3. If it's sometimes one object, wrap it: [].concat($json.tags ?? []) always gives you an array.
  4. If the previous node outputs one item per element, you don't need .map() at all — use $json.field directly, 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\"]"
}
.map(t => t.toUpperCase())

⚙️ Your fix is executed against both test items — any correct solution passes.

📖 n8n map() reference →

Was this page helpful?

Practice the skill behind this fix

More n8n errors