items = _input.all()validated = []for item in items: data = item["json"] errors = [] if not data.get("email") or "@" not in data.get("email", ""): errors.append("Invalid email") if not data.get("name") or not data.get("name", "").strip(): errors.append("Name required") validated.append({ "json": { **data, "name": data.get("name", "").strip(), "email": data.get("email", "").lower().strip(), "valid": len(errors) == 0, "errors": errors if errors else None } })return validated
5. Statistical analysis
from statistics import mean, median, stdevitems = _input.all()values = [item["json"].get("value", 0) for item in items if "value" in item["json"]]if values: return [{ "json": { "mean": mean(values), "median": median(values), "stdev": stdev(values) if len(values) > 1 else 0, "min": min(values), "max": max(values), "count": len(values) } }]else: return [{"json": {"error": "No values found"}}]
# ❌ WRONG: ModuleNotFoundErrorimport requestsimport pandas# ✅ CORRECT: Use HTTP Request node before the Code node# OR switch to JavaScript and use $helpers.httpRequest()
#2: Missing return statement
# ❌ WRONG: No returnitems = _input.all()# Processing...# Forgot to return!# ✅ CORRECT: Always returnitems = _input.all()# Processing...return [{"json": item["json"]} for item in items]
#3: Incorrect return format
# ❌ WRONG: dict without listreturn {"json": {"result": "success"}}# ✅ CORRECT: list with dictreturn [{"json": {"result": "success"}}]
#4: KeyError on dictionary access
# ❌ WRONG: Direct access crashes if key is missingname = _json["user"]["name"] # KeyError if user or name doesn't exist# ✅ CORRECT: Use .get() with safe chainingname = _json.get("user", {}).get("name", "Unknown")
#5: Webhook body nesting
# ❌ WRONG: Webhook data is not at _json rootemail = _json["email"] # KeyError!# ✅ CORRECT: Webhook data is under ["body"]email = _json["body"]["email"]# ✅ SAFER: .get() for safe accessemail = _json.get("body", {}).get("email", "no-email")
# 1. Always use .get() for dictionary accessvalue = item["json"].get("field", "default") # Safe# value = item["json"]["field"] # Risky# 2. Handle None/null explicitlyamount = item["json"].get("amount") or 0# 3. Use list comprehensions for filteringvalid = [item for item in items if item["json"].get("active")]# 4. Return consistent structurereturn [{"json": result}] # Single resultreturn results # Multiple (already formatted)return [] # No results# 5. Debug with print()print(f"Processing {len(items)} items")print(f"First item: {items[0] if items else 'None'}")