Datawave (2)
Datawave (2)
-------------------------------------------
whenever error occured in flow an error object is created
it contains error.description,error.errorType, errortype is nothing but combination of
Namespace and Identifier
EG:: DB:connectivity,http:unauthorized
1) Input:::
"xyz,abc,apq"
OutPut:::
{
"A1":"xyz",
"A2":"abc",
"A3":"apq"
}
Mpping:::
%dw 2.0
output application/json
---
payload splitBy(",")
%dw 2.0
output application/json
var D =["A1","A2","A3"]
---
payload map((D[$$]):$) reduce (item,acc={})-> acc ++ item
-------------------------------------------------------------------------
2) Input:::
[{
"A1":"N",
"A2":"sathish"
},{
"A1":"reddy",
"A2":"SSSS"
}]
OutPut:::
{
"N":"satish",
"reddy":"SSSS"
}
Mpping::::
%dw 2.0
output application/json
---
payload map((item,index)->(item.A1):item.A2) reduce (item,acc={})-> acc ++ item
///////// OR ///////
%dw 2.0
output application/json
---
payload map(($.A1):$.A2) reduce (item,acc={})-> acc ++ item
---------------------------------------------------------------------------
3) Input:::
{
"pratice":[1,2,3,4,5]
}
Output:::
[2,3,4,5,6]
Mapping:::
%dw 2.0
output application/json
---
payload.message map ((item, index) -> item+1)
//////////OR/////////
%dw 2.0
output application/json
---
payload.message map ($+1)
---------------------------------------------------------------------------
4) Input:::
[
{"Id":1,"name":"satish"},
{"Id":2,"name":"reddy"},
{"Id":3,"name":"reddy"}
]
want only Id
Output:::
[
1,
2,
3
]
Mapping:::
%dw 2.0
output application/json
---
payload map ($.Id)
-----------------------------------------------------
4)Input:::
[{
"name":"satish",
"jobs":[{"role": "developer"},
{"role": "tester"},
{"role": "actor"}
]
},{
"name":"satish",
"jobs":[{"role": "doctor"},
{"role": "teacher"},
{"role": "Roller"}
]
}]
Output:::
[
{
"name": "satish",
"jobs": [
{
"Id": 0,
"role": "developer"
},
{
"Id": 1,
"role": "tester"
},
{
"Id": 2,
"role": "actor"
}
]
},
{
"name": "satish",
"jobs": [
{
"Id": 0,
"role": "doctor"
},
{
"Id": 1,
"role": "teacher"
},
{
"Id": 2,
"role": "Roller"
}
]
}
]
Mapping::::
%dw 2.0
output application/json
---
payload map(item,index)->{
"name":item.name,
"jobs":item.jobs map(item,index)->{
Id:index,
role:item.role
}
}
5)Input:::
[1,2,4,7,9,10,99,100,44,77,22]
Output:::
Deviible By 2
Mppaing:::
%dw 2.0
output application/json
---
Diveded By 2::
payload filter (item, index) -> (mod(item,2))==0,
ODD Numbers::
payload filter ((item, index) -> isOdd(item))
Even Numbers::
payload filter ((item, index) -> isEven(item))
ODD Index::
payload filter ((item, index) -> isOdd(index))
Even Index::
payload filter ((item, index) -> isOdd(index))
6) Input::
[
{
"Id": 1,
"Statuse": "Load"
},
{
"Id":2,
"Statuse": "AIM"
},
{
"Id": 3,
"Statuse": "Shut"
}
]
OUTPUT:::
[
{
"Id": 1,
"Statuse": "Load"
},
{
"Id": 2,
"Statuse": "AIM"
}
]
Mapping:::
%dw 2.0
output application/json
---
payload filter ((item, index) -> item.Id !=3 )
7) INPUT::
[
"satish",
"sita",
"jshd",
"jwkfj"
]
Output:::
[
"jshd",
"jwkfj"
]
Mapping:::
%dw 2.0
output application/json
var F=["satish","sita"]
---
//payload filter ((item, index) -> !(item == "satish" or item == "sita" or item == "jshd"))
payload filter (item, index) -> !(item == F[0] or item == F[1] )
8)
Input::
{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": null
}
Output:::
{
"A": "SATISH",
"B": "SITA",
"C": "JSHD",
"D": "JWKFJ"
}
MAPPING:::
9)
INPUT:::
{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": "null"
}
OUPUT:::
[
["a", "satish"],
["b","sita"],
["c","jshd"],
["d","jwkfj"],
["e", "null"]
]
MAPPING:::
%dw 2.0
output application/json
---
//payload pluck ((value, key, index)-> (upper(key)):upper(value))
payload pluck ((value, key, index) -> [key,value])
10)
INPUT::
{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": "null"
}
Output::::
[
{
"A": "SATISH"
},
{
"B": "SITA"
},
{
"C": "JSHD"
},
{
"D": "JWKFJ"
},
{
"E": "NULL"
}
]
MAPPING:::
%dw 2.0
output application/json
var F=["satish","sita"]
---
payload pluck ((value, key, index)-> (upper(key)):upper(value))
//payload pluck ((value, key, index) -> [key,value])
11)
INPUT:::
surename=nemalidinne;
name=sathish;
middlename=reddy;
rank=312
OUTPUT:::
{
"surename": "nemalidinne",
"name": "sathish",
"middlename": "reddy",
"rank": "312"
}
Mapping:::
%dw 2.0
output application/json
---
payload splitBy(";") map ((item, index) -> item splitBy ("=")) reduce ((item, accumulator=
{}) ->accumulator++(item[0]):item[1] )
OR
payload splitBy ";" map ((item, index) ->item splitBy "=" ) map ((item, index) ->
(item[0]):item[1] )reduce($$++$)
-------------------------------------------------------------
12)
INPUT:::
[
{
"product name":"bread",
"ExpairyDate":"11/01/2011",
"Price": 40
},
{
"product name":"Apple",
"ExpairyDate":"22/12/2012",
"Price": 60
},
{
"product name":"wine",
"ExpairyDate":"13/11/2022",
"Price": 30
},
{
"product name":"milk",
"ExpairyDate":"12/11/2039",
"Price": 140
}
]
OUTPUT::::
[
30,
140
]
Mapping:::
%dw 2.0
output application/json
var TodayDate = now() as Date {format:"dd/MM/yyyy"}
var DD = payload filter $.ExpairyDate>TodayDate
---
(payload filter $.ExpairyDate>TodayDate).Price
13)
INPUT:::
{"ID":"123_(456)_(789)"}
OUTPUT::
789
MAPPING:::
%dw 2.0
output application/json
---
((payload.ID splitBy("_"))[2] replace "(" with "" replace ")" with "") as Number
14)
INPUT::
[{
"Id": 1234,
"Name": "salary Account",
"Type": "Salary",
"chaild account":[
{
"Name":"personal",
"Type":"Self",
"Id": 987
},{
"Name":"Loan Account",
"Type":"Loan",
"Id": 654
}
]
}]
OUTPUT::
[
{
"ID": 1234,
"Name": "salary Account"
},
{
"Name": "personal",
"ID": 987
},
{
"Name": "Loan Account",
"ID": 654
}
]
MAPPING::
%dw 2.0
output application/json
var S = payload map(item,index)->{
"ID":item.Id,
"Name":item.Name
}
var R=flatten(payload.chaildaccount map(item)-> item map(item2)->{
"Name":item2.Name,
"ID":item2.Id
})
---
S ++ R
---------------------------------------------------------------------
14)
INPUT:::
"mulesoft,12"
OUTPUT:::
"SDAR , 90"
Mapping:::
%dw 2.0
output application/json
fun first(item1:String,item2:Number)=
upper(item1) ++ " , " ++ item2*10
---
first("sdar",9)
15)
INPUT:::
{
"parent":{
"OrderID":"123",
"price":"12",
"Chaild1":{
"OrderID": "456",
"price": "34"
},
"Chaild2":{
"OrderID": "789",
"price": "27"
}
}
}
OUTPUT:::
sum of all the Pricess.
MAPPING:::
%dw 2.0
output application/json
---
payload.parent..price reduce($ + $$)
sum (payload..price)
------------------------------------------
16)
INPUT:::
[1,33,56,74,989,45,89]
OUTPUT:::::
Assinding Order or desinding Order
MAPPING:::
%dw 2.0
output application/json
---
//(payload orderBy $) [-1 to 0]
payload orderBy -$
17)
INPUT:::
[{
"name": "satish",
"jobs":[{
"type": "Developer"},
{
"type":"tester"
},
{
"type":"actor"
}
]},{
"name":"Anil",
"jobs":[{
"type":"farmer"
},{
"type":"Leader"
},{
"type":"Traveler"
}
]}]
OUTPUT:::
[
{
"id header": 1,
"name": "satish",
"jobs": [
{
"id chaild": 200,
"type": "Developer"
},
{
"id chaild": 201,
"type": "tester"
},
{
"id chaild": 202,
"type": "actor"
}
]
},
{
"id header": 2,
"name": "Anil",
"jobs": [
{
"id chaild": 200,
"type": "farmer"
},
{
"id chaild": 201,
"type": "Leader"
},
{
"id chaild": 202,
"type": "Traveler"
}
]
}
]
MAPPING:::
%dw 2.0
output application/json
---
flatten(payload map ((item, index) -> {
"id header":index+1,
"name":item.name,
"jobs": item.jobs map(data,index1)->{
"id chaild":index1+200,
"type":data."type"
}
}))
18)
INPUT:::
{
"product_name": [{
"Id": 123,
"name": "satish"
},
{
"id": 456,
"name": "reddy"
},
{
"id": 789,
"name": "nemalidinne"
}
],
"product_price": [{
"id": 123,
"price": 1000
},
{
"id": 456,
"price": 2000
},
{
"id": 789,
"price": 3000
}
]
}
OUTPUT:::
[
{
"id": 123,
"price": 1000
},
{
"id": 456,
"price": 2000
},
{
"id": 789,
"price": 3000
}
]
MAPPING::
%dw 2.0
output application/json
---
flatten(payload.product_name map(item1)->payload.product_price filter ((item2,index) -
>item2.id==item1.id ))
19)
INPUT:::
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
]
OUTPUT:::
[
0,
2,
4,
6,
8,
10,
[
1,
3,
5,
7,
9
]
]
MAPPING:::
%dw 2.0
output application/json
var S = payload map if(isEven($)) {even:$} else{odd:$}
var G = payload map if(mod ($, 2) == 0) {even:$} else{odd:$}
---
G.even + G.odd
//S.odd + S.even
20)
INPUT:::
[{
"CartPlace": "Order_Complete",
"currency": "INR",
"subtotal": 13,
"discount Amount": 2,
"emailAddrees": "[email protected]",
"orderId": "A123B",
"ShippingAmount": "7_34",
"Shipping_date": "01/10/2022",
"ShippingDetails": "fedex"
}, {
"CartPlace": "Order_Complete",
"currency": "USA",
"subtotal": 56,
"discount Amount": 3,
"emailAddrees": "[email protected]",
"orderId": "A123B",
"ShippingAmount": "07_4",
"Shipping_date": "01/12/2022",
"ShippingDetails": "Demart"
}]
OUTPUT:::
1) convert to csv,
2)remove email and currency,
3) separator with |,
4) leftPad 14,
MAPPING:::
%dw 2.0
import * from dw::core::Strings
output application/csv header=false,separator= "|"
var s=payload map ($ -"currency" - "emailAddrees")
var R= payload map (data)->data mapObject ((value, key, index) -> (key):leftPad(value,14,7))
---
R ++ s
-------------------------------------------------------------------------------
21)
INPUT:::
DISPLAYOnly Date using now function
Output::
"18/10/2022"
Mapping::::
%dw 2.0
output application/json
---
now() as String{format:"dd/MM/yyyy"}
------------------------------------------
22)
Input::
{
"A":[1,2,3,4],
"B":[5,6,[7,8,9],0]
}
---------------------------------------------------------
30)
INPUT:::
[1,12,23,34]
OUTPUT::::
[
{
"values": 1,
"v *10": 10,
"index": 0,
"The value After": 12
},
{
"values": 12,
"v *10": 120,
"index": 1,
"The value After": 23
},
{
"values": 23,
"v *10": 230,
"index": 2,
"The value After": 34
},
{
"values": 34,
"v *10": 340,
"index": 3,
"The value After": null
}
]
MAPPING:::::
%dw 2.0
output application/json
---
payload map ((item, index) ->{
"values":item,
"v *10":item *10,
"index":index,
"The value After": payload[index+1]
} )
31)INPUT:::
{
"Tablelist":[
{
"Name": "nemalidinne_satish_reddy"
},{
"Name": "nemalidinne_ANIL_reddy"
},{
"Name": "Madhinnene_SAI_Chowdery"
},{
"Name": "Vadlamudi_Singhaia_Chowdary"
},{
"Name": "Vadlamudi_vamsi_Chowdary"
}
]
}
OUTPUT:::
[
{
"index": 20,
"J": "nemalidinne",
"K": [
{
"S": "nemalidinne",
"T": "satish_reddy"
},
{
"S": "nemalidinne",
"T": "ANIL_reddy"
}
]
},
{
"index": 21,
"J": "Madhinnene",
"K": [
{
"S": "Madhinnene",
"T": "SAI_Chowdery"
}
]
},
{
"index": 22,
"J": "Vadlamudi",
"K": [
{
"S": "Vadlamudi",
"T": "Singhaia_Chowdary"
},
{
"S": "Vadlamudi",
"T": "vamsi_Chowdary"
}
]
}
]
MAPPING:::
%dw 2.0
output application/json
---
(payload.Tablelist map ((item, index) ->
using (data=item.Name splitBy("_"))
{
"S":data [0],
"T":data [1 to 2] joinBy "_"
} ))groupBy ((item, index) -> item.S) pluck ((value, key, index) -> {
"index":index+20,
"J":key,
"K":value,
})
32))
INPUT:::
[{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
}
]
OUTPUT:::
[
{
"ID": "a",
"VAL": 4
},
{
"ID": "b",
"VAL": 8
},
{
"ID": "c",
"VAL": 12
},
{
"ID": "d",
"VAL": 16
}
]
MAPPING::::
%dw 2.0
output application/json
---
flatten(payload map ((item, index) ->item.ID map ((item1, index1) ->{
ID:item1,
Val:item.val[index1]
} ))) groupBy ((item, index) ->item.ID )pluck ((value, key, index) ->{
ID:key,
VAL:value.Val reduce($+$$)
})
33)INPUT::::
[{
"ordernumber": 123,
"itemnumber": "111",
"RequistDate": "2022-05-26"
},{
"ordernumber": 456,
"itemnumber": "187",
"RequistDate": "2022-06-30"
},{
"ordernumber": 789,
"itemnumber": "0987",
"RequistDate": "2021-06-26"
},{
"ordernumber": 312,
"itemnumber": "312",
"RequistDate": "2022-05-27"
},{
"ordernumber": 123,
"itemnumber": "111",
"RequistDate": "2022-05-28"
}]
OUTPUT:::
[
{
"OrderNumber": "123",
"LineItem": [
{
"RequistDate": "2022-05-26",
"ItemNumber": "111"
}
]
},
{
"OrderNumber": "456",
"LineItem": [
{
"RequistDate": "2022-06-30",
"ItemNumber": "187"
}
]
},
{
"OrderNumber": "789",
"LineItem": [
{
"RequistDate": "2021-06-26",
"ItemNumber": "0987"
}
]
},
{
"OrderNumber": "312",
"LineItem": [
{
"RequistDate": "2022-05-27",
"ItemNumber": "312"
}
]
}
]
MAPPING::::
%dw 2.0
output application/json
---
payload distinctBy $.ordernumber groupBy ((item, index) -> item.ordernumber)pluck ((value,
key, index) ->{
"orderNumber":key,
"LineItems":value map ((item, index) -> {
"RequistDate":item.RequistDate,
"itemNumber":item.itemnumber
})
} )
34)
INPUT:::
{
"name":"sathishReddy",
"Place":"Hyderabad",
"Job":"Software"
}
OUTPUT:::
{
"name": "sathishReddy",
"Place": "nrt",
"Job": "Software"
}
Mapping:::
%dw 2.0
output application/json
---
/*payload mapObject((value, key, index) ->{
(key):if(value=="Hyderabad") "A.muppalla" else value
} )*/
payload update {
case satish at .Place -> "nrt"
}
35)
INPUT:::
{
"businessunits": [
{
"code":"IT",
"name":"Information Technology"
}, {
"code":"BPS",
"name":"Bussiness Processing Services"
}, {
"code":"BPO",
"name":"Bussiness Processing Services"
}
],
"Division":[
{
"code":"AM",
"name":"Administation",
"business":"IT"
},{
"code":"TS",
"name":"Technical Services",
"business":"IT"
},{
"code":"ES",
"name":"Administation",
"business":"BPO"
},{
"code":"PS",
"name":"Photoshop Serices",
"business":"PSO"
}
]
}
OUTPUT:::
[
{
"name": "Information Technology",
"code": "IT",
"Dname": "Administation",
"Dcode": "AM"
},
{
"name": "Information Technology",
"code": "IT",
"Dname": "Technical Services",
"Dcode": "TS"
},
{
"name": "Bussiness Processing Services",
"code": "BPS",
"Dname": null,
"Dcode": null
},
{
"name": "Bussiness Processing Services",
"code": "BPO",
"Dname": "Administation",
"Dcode": "ES"
}
]
MAPPING::::
%dw 2.0
output application/json
import * from dw::core::Arrays
var A= payload.businessunits
var B= payload.Division
---
leftJoin(A,B,(A)->A.code,(B)->B.business)map ((item, index) ->{
"name":item.l.name,
"code":item.l.code,
"Dname":item.r.name,
"Dcode":item.r.code
} )
36)
INPUT::
[{
"resource":"SalesOrgToMap",
"resourceId":"110",
"destination":{
"agialoftinstancename":"APAC",
"url":"https://test.appis.com:37158/s1/"
},
"destnationType":"SystemAPI",
"perameters":{
"OrgCode":"RD_ID",
"SalesOrg":"12345",
"interfacedID":"CreateContractInterface"
}
},
{
"resource":"SalesOrgToMap",
"resourceId":"1101",
"destination":{
"agialoftinstancename":"APAC",
"url":"https://test.appis.com:37158/s1/"
},
"destnationType":"SystemAPI",
"perameters":{
"OrgCode":"RD_LD",
"SalesOrg":"09886",
"interfacedID":"CrReateContractInterface"
}}]
OutPUT::::
[
{
"resource": "SalesOrgToMap",
"resourceId": "110",
"destination": {
"agialoftinstancename": "APAC",
"url": "https://test.appis.com:37158/s1/"
},
"destnationType": "SystemAPI",
"perameters": {
"OrgCode": "RD_ID",
"SalesOrg": "12345",
"interfacedID": "CreateContractInterface"
}
},
{
"resource": "SalesOrgToMap",
"resourceId": "1101",
"destination": {
"agialoftinstancename": "APAC",
"url": "https://test.appis.com:37158/s1/"
},
"destnationType": "SystemAPI",
"perameters": {
"OrgCode": "RD_LD",
"SalesOrg": "09886",
"interfacedID": "CrReateContractInterface"
}
}
]
Mapping:::
%dw 2.0
output application/json
var S={
"OrgCode":"RD_ID",
"SalesOrg":"12345"
}
fun Checklist(dataitem,S)=do{ var temp=(S mapObject ((value, key, index) -> data :
dataitem.perameters[key] == S[key])).*data
---
temp == temp filter($!=false)
}
---
payload filter ((item, index) ->
Checklist(item,S)
)
37)
INPUT:::
{
"communication": [
{
"sourceId": "226",
"domain": "mule",
"customers": [
{
"sType": "wire",
"mode": "EMAIL",
"category": "DAY_AFTER_EXPIRE",
"ctn": [
"771779"
],
"Type": "I",
"langPreference": "EN",
"eventSentTime": "11-16-2022T12:44:26 +0000",
"accNo": "1770"
}
],
"destination": "SF",
"Req": true
}
]
}
OUTPUT::
[
{
"sourceID": "226",
"domain": "mule",
"customers": [
{
"sType": "wire",
"mode": "EMAIL",
"category": "DAY_AFTER_EXPIRE",
"ctn": [
"771779"
],
"Type": "I",
"langPreference": "EN",
"eventSentTime": "11-16-2022T12:44:26 +0000",
"accNo": "1770"
}
],
"notifications": [
{
"eventType": ""
}
],
"destination": "SFDC",
"req": true,
"accountSreq": true
}
]
MAPPING:::
38)
INPUT::
[{
"name":"satish",
"ID": 312,
"Tag":"hero"
},
{
"logic":"hjw",
"magic":"hgd"
}]
OUTPUT:::
[
{
"name": "ANIL",
"ID": 123,
"Tag": "SUPERHERO"
},
{
"logic": "datawave",
"magic": "jka"
}
]
MAPPING:::
%dw 2.0
import update,field from dw::util::Values
output application/json
---
payload update "name" with upper("anil") update "logic" with "datawave" update "ID" with 123
update "magic" with "jka" update "Tag" with upper( ("Super" ++ "hero"))
39)
INPUT:::
[{"name": "Ken", "age": 30},
{"name": "Tomo", "age": 70},
{"name": "Kajika", "age": 10}]
OUTPUT::::
[
{
"name": "SATISH",
"age": 77
},
{
"name": "Tomo (hdagf)",
"age": 42
},
{
"name": "Kajika",
"age": 10
}
]
MAPPING:::
%dw 2.0
output application/json
---
payload map(item)->item update {
case AA at .age if(AA == 30) -> 77
case SS at .age if(SS==70)->42
case ZZ at .name if(ZZ=="Tomo")-> ZZ ++ " (hdagf)"
case XX at .name if(XX=="Ken")-> upper("satish")
}
40)
INPUT:::
{
"message": "helloabc",
"name":"hellodce"
}
Output:::
"acde"
Mapping:::
%dw 2.0
output application/json
import * from dw::core::Strings
var A=payload.message [5 to 7] remove "b"
var B=payload.name[5 to 7] remove "c"
---
A ++ B
41)
INPUT::
[{
"business":{
"ID":"rel",
"desc":"rel industry",
"industry":{
"ID":"manufacture",
"desc":"manufacturing",
"Businessline":{
"ID":"residential",
"desc":"residential manufacture",
"facility":{
"ID":"mumbai",
"desc":"mumbai location"
}
}
}
}
}]
OUTPUT:::
{
"asset": [
{
"key": "rel",
"desc": "rel industry"
},
{
"key": "manufacture",
"desc": "manufacturing",
"parent": [
"rel"
]
},
{
"key": "residential",
"desc": "residential manufacture",
"parent": [
"rel-manufacture"
]
},
{
"key": "mumbai",
"desc": "mumbai location",
"parent": [
"rel-manufacture-mumbai"
]
}
]
}
MAPPING:::
%dw 2.0
output application/json
var A=payload map ((item, index) ->{
"key":item.business.ID,
"desc":item.business.desc
} )
var B=payload map ((item, index) ->{
"key":item.business.industry.ID,
"desc":item.business.industry.desc,
"parent":[item.business.ID]
} )
var C=payload map ((item, index) ->{
"key":item.business.industry.Businessline.ID,
"desc":item.business.industry.Businessline.desc,
"parent": [(item.business.ID)++"-"++(item.business.industry.ID)]
} )
var D=payload map ((item, index) ->{
"key":item.business.industry.Businessline.facility.ID,
"desc":item.business.industry.Businessline.facility.desc,
"parent": [(item.business.ID) ++"-"++ (item.business.industry.ID) ++"-"++
(item.business.industry.Businessline.facility.ID)]
} )
---
//{"asset":[A+B+C+D] reduce($++$$)}
{"asset":A ++ B ++ C ++ D}
42)INPUT:::
{
"key":"hellow world ",
"key1":"satish reddy",
"key2":"nemalidinne satish"
}
OUTPUT::::
{
"key": "hellow world",
"key1": "satish reddy",
"key2": "nemalidinne satish"
}
MAPPING::::
%dw 2.0
output application/json
import * from dw::core::Strings
fun removeSpace(StartData)=if(StartData[-1]==" ")removeSpace(StartData[0 to-2]) else
StartData
---
payload mapObject ((value, key, index) ->{
(key):removeSpace(value)
})
-----------------OR-----------------
%dw 2.0
output application/json
---
payload mapObject ((value, key, index) ->(key):value replace " " with "" )
43)
INPUT:::
{
"order": {
"place": {
"name": {
"firstName": "sachin",
"lastname": "tendulcurr",
"asisselm": {
"asile": "IT",
"asile": "Batsman",
"asile": "India"
}
}
}
},
"order": {
"place": {
"name": {
"firstName": "mahi",
"lastname": "sing",
"asisselm": {
"asile": "dhoni",
"asile": "Batsman",
"asile": "jarkand"
}
}
}
}
}
OUTPUT:::
[
{
"asisslem": "IT",
"Lastname": "tendulcurr"
},
{
"asisslem": "Batsman",
"Lastname": "tendulcurr"
},
{
"asisslem": "India",
"Lastname": "tendulcurr"
},
{
"lastname": "sing",
"asisslem": "dhoni"
},
{
"lastname": "sing",
"asisslem": "Batsman"
},
{
"lastname": "sing",
"asisslem": "jarkand"
}
]
MAPPING::
%dw 2.0
output application/json
var A=([payload] map ((item, index) ->item.order.place.name.asisselm pluck ((value, key,
index) ->{
"asisslem":value,
"Lastname":item....lastname[0]
} )))[0]
var B=flatten([payload[1]] map ((item, index) ->item.place.name.asisselm pluck ((value, key,
index) ->{
"lastname":item.place.name.lastname,
"asisslem":value
} ) ))
---
flatten(A+B)
.
------------------------------------------ Connectors -----------------------------------
----------------------
--------------------------------------------------------------------------------------------
----------------------
FORECH SCOPE::
Forech is like loope which runs Sequencelly (one by one)