Data Transformation
Data Transformation ဆိုတာ ဘာလဲ?
Section titled “Data Transformation ဆိုတာ ဘာလဲ?”Real-world Workflow တွေမှာ API တစ်ခုကနေ Data ယူပြီး App တစ်ခုမှာ ထည့်တဲ့အခါ Format ကွာနိုင်ပါတယ်။ Data Transformation ဆိုတာ ထို Format Mismatch ကို ဖြေရှင်းတာပါ:
- Source API ၏
user_name→ Slack ၏username - Source API ၏
date_ts→ Slack ၏text - Source API ၏
amount→ Slack ၏blocks
Set Node — Field ပြောင်းလဲခြင်း
Section titled “Set Node — Field ပြောင်းလဲခြင်း”Set Node သည် Data ထဲ Field များ ထည့်ရန်၊ ပြင်ရန်၊ ဖျက်ရန် သုံးသည်:
Mode 1: Manual Mapping
Section titled “Mode 1: Manual Mapping”Visual ဖြင့် Field တစ်ခုချင်းစီ သတ်မှတ်သည်:
| Name (field) | Value |
|---|---|
fullName | {{ $json.first + " " + $json.last }} |
email | {{ $json.email.toLowerCase() }} |
joinedAt | {{ $now.toISO() }} |
Mode 2: JSON
Section titled “Mode 2: JSON”Output JSON ကို တိုက်ရိုက် ရေးနိုင်သည်:
{ "fullName": "={{ $json.first + ' ' + $json.last }}", "email": "={{ $json.email.toLowerCase() }}", "status": "active"}Code Node — Complex Transformation
Section titled “Code Node — Complex Transformation”Complex Logic တွေအတွက် JavaScript / Python ကို Code Node ထဲ ရေးနိုင်သည်:
ဥပမာ: API Data ကို ပြင်ဆင်ခြင်း
Section titled “ဥပမာ: API Data ကို ပြင်ဆင်ခြင်း”// Code Node - JavaScript// API မှ orders list ကို ရရှိပြီး ပြုပြင်ရန်
return $input.all().map(item => { const order = item.json;
return { json: { orderId: order.id, customer: `${order.billing.first_name} ${order.billing.last_name}`, total: `$${(order.total / 100).toFixed(2)}`, status: order.status.toUpperCase(), date: new Date(order.date_created).toLocaleDateString('my-MM'), itemCount: order.line_items.length } };});Python Mode
Section titled “Python Mode”# Code Node - Pythonresult = []
for item in _input.all(): order = item['json'] result.append({ 'json': { 'id': order['id'], 'total': f"${order['total'] / 100:.2f}", 'status': order['status'].upper() } })
return resultIF Node — Conditional Branching
Section titled “IF Node — Conditional Branching”IF Node သည် Condition စစ်ပြီး Data ကို ၂ ခု (True / False) ခွဲပေးသည်:
IF Node Configuration
Section titled “IF Node Configuration”Condition: {{ $json.amount }} > 100
Value 1: {{ $json.amount }} (Number) Operation: Greater Than Value 2: 100Multiple Conditions
Section titled “Multiple Conditions”AND Condition (၂ ခုလုံး True ဖြစ်ရမည်): amount > 100 AND status === "completed"
OR Condition (တစ်ခုမှ True ဖြစ်ရုံနဲ့): status === "pending" OR status === "processing"Switch Node — Multiple Paths
Section titled “Switch Node — Multiple Paths”Switch Node သည် IF ကဲ့သို့ ဖြစ်သော်လည်း Path ၂ ခုထက် ပိုသောအခါ သုံးသည်:
Switch Node — Status ပေါ်မူတည်ပြီး Path ၃ ခုခွဲသည်
Switch Node Configuration:
Mode: Rules
Case 1: {{ $json.status }} === "pending" → Output 0Case 2: {{ $json.status }} === "shipped" → Output 1Case 3: {{ $json.status }} === "delivered" → Output 2Default: → Output 3Merge Node — Data ပေါင်းခြင်း
Section titled “Merge Node — Data ပေါင်းခြင်း”Node ၂ ခု မှ Data ကို ပေါင်းရာတွင် Merge Node ကို သုံးသည်:
Merge Node Modes:
- Append — A items + B items (ပေါင်းထည့်)
- Combine — Field တူသည်ကို Match ပြီး Join
- Choose Branch — A or B ကို Condition ဖြင့် ရွေး
ဥပမာ — User & Order Data ပေါင်းခြင်း:
[Get User from DB] ──▶ ┌──────────────┐ │ Merge Node │──▶ { user + order }[Get Order from API]──▶│ (Combine) │ └──────────────┘
Merge by: user_id (common field)n8n Expressions — Built-in Functions
Section titled “n8n Expressions — Built-in Functions”n8n Expression တွင် Built-in Helper Functions များ ရှိသည်:
String Functions
Section titled “String Functions”{{ $json.name.toUpperCase() }} → "AUNG AUNG"{{ $json.email.toLowerCase() }} → "aung@gmail.com"{{ $json.text.trim() }} → Whitespace ဖျက်{{ $json.name.includes("Aung") }} → true / false{{ $json.title.slice(0, 50) }} → ပထမ ၅၀ CharacterNumber Functions
Section titled “Number Functions”{{ Math.round($json.price) }} → Round{{ Number($json.amount).toFixed(2) }} → 2 decimal places{{ $json.items.length }} → Array အရေအတွက်Date Functions
Section titled “Date Functions”{{ $now.toISO() }} → "2025-01-15T09:00:00.000Z"{{ $now.toFormat('yyyy-MM-dd') }} → "2025-01-15"{{ $now.plus({days: 7}).toISO() }}→ 7 ရက်ကြာ DatePractical: E-commerce Order Processing
Section titled “Practical: E-commerce Order Processing”ဤ Workflow သည် Order တစ်ခုဝင်လာသောအခါ Customer Status ပေါ်မူတည်ပြီး Email ကွဲပြားစွာ ပို့သည်:
// Set Node (VIP Path){ "emailTemplate": "vip", "subject": "VIP Order Confirmation + Free Shipping!", "discount": 10}
// Set Node (Standard Path){ "emailTemplate": "standard", "subject": "Order Confirmed!", "discount": 0}နောက်သင်ခန်းစာမှာ Real-World Automation Workflows တွေကို လေ့လာကြပါမည်!