I want to transfrom the xml to json while an element "Coll" in the incoming xml will be an array if single object received. Result.Coll needs to be an array object rest will be same.
<Result xmlns="http://ws.apache.org/ns/synapse">
<ban:DOB xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema">22101991</ban:DOB>
<ban:TDNPFlag xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema">N</ban:TDNPFlag>
<ban:DNPExpryDt xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema"/>
<ban:NibbsBVN xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema"/>
<ban:Fac xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema"/>
<ban:Coll xmlns:ban="http://TCS.BANCS.Adapter/BANCSSchema">
<ban:AcctNum>10205781559</ban:AcctNum>
<ban:Stat>DISC</ban:Stat>
<ban:ChqbkFlag/>
<ban:CardFlag/>
</ban:Coll>
</Result>
Result for above
{"Result":{"CustNum":"00000002010784868","CustTyp":"01","RelnshpMgr":"0","Title":"1","Name":"Mr Tebogo Sekalaba","Addr1":"Botswana","Addr2":"","Addr3":"","Addr4":"","PstCode":"","HomePhnNum":"","FaxNum":"","CountryOfRes":"BW","BussPhnNum":"","MobileNum":"71961292","Natlty":"BW","NumOfChqbk":"00","NumOfCard":"00","FacltyCnt":"0000","CustLmt":"0.00","TtlBal":"-601.40","CurCode1":"BWP","ResInd":"","UsrName":"NO TELLER NAME","StmtFreq":"H","StmtCyc":"00","StmtDay":"31","GrpCode":"","AvgEodBal":"0.00","FatherName":"","BlackLstInd":"N","EmplInd":"","BlackLstStat":"0","BlackLstComnt":"","CreditRtng":"0","CustStat":"0","IdNum":"652311945","VipStat":"0","AccumCnt1":"0","AccumCnt2":"0","AccumCnt3":"0","AccumCnt4":"0","AccumCnt5":"0","AccumCnt6":"0","AccumCnt7":"0","AccumCnt8":"0","AccumCnt9":"0","AccumCnt10":"0","EmailAdd":"","LagCode":"1","BrchCode":"35","RtnMailInd":"N","HldMail":"","Typ":"","VipTyp":"","name1":"Mr","name2":"","CreateDt":"19092023","MemShpLnth":"124 YEARS 003 MONTHS","CurrAge":"032 YEARS 004 MONTHS","ServLnth":"","RemainServ":"","AvailChnl1":"","AvailChnl2":"","AvailChnl3":"","AvailChnl4":"","AvailChnl5":"","AvailChnl6":"","AvailChnl7":"","AvailChnl8":"","BioEnrollDt":"99999999","BioEnrollTime":"00:00:00","KYCFlag":"H","IdTyp":"0001","DOB":"22101991","TDNPFlag":"N","DNPExpryDt":"","NibbsBVN":"","Fac":"","Coll":{"AcctNum":"10205781559","Stat":"DISC","ChqbkFlag":"","CardFlag":"","AcctFlagTyp":"L","ProdDescptn":"MoMo Instant Loan","CurCode2":"BWP","RelnshpWtAcct":"OWN","Bal":"601.40","OvrdrftAcctLmt":"500.00","AcctTyp":"5000","AcctSubTyp":"0555","ShrtName":"","InstNum":"002","TagStat":"","LonOdAmt":"500.00","ArrAcctAmt":"560.00","Dpd":"2","OdInd":"","HowLong":"0.46","IBAN":"","AcctBrch":"35","CreationDt":"19092023","Acctstat":"40","PurpCod":"27","SignMndt":"","SignDetail":"","SignatoryNum":"0"}}}
Expected output
{"Result":{"CustNum":"00000002010784868","CustTyp":"01","RelnshpMgr":"0","Title":"1","Name":"Mr Tebogo Sekalaba","Addr1":"Botswana","Addr2":"","Addr3":"","Addr4":"","PstCode":"","HomePhnNum":"","FaxNum":"","CountryOfRes":"BW","BussPhnNum":"","MobileNum":"71961292","Natlty":"BW","NumOfChqbk":"00","NumOfCard":"00","FacltyCnt":"0000","CustLmt":"0.00","TtlBal":"-601.40","CurCode1":"BWP","ResInd":"","UsrName":"NO TELLER NAME","StmtFreq":"H","StmtCyc":"00","StmtDay":"31","GrpCode":"","AvgEodBal":"0.00","FatherName":"","BlackLstInd":"N","EmplInd":"","BlackLstStat":"0","BlackLstComnt":"","CreditRtng":"0","CustStat":"0","IdNum":"652311945","VipStat":"0","AccumCnt1":"0","AccumCnt2":"0","AccumCnt3":"0","AccumCnt4":"0","AccumCnt5":"0","AccumCnt6":"0","AccumCnt7":"0","AccumCnt8":"0","AccumCnt9":"0","AccumCnt10":"0","EmailAdd":"","LagCode":"1","BrchCode":"35","RtnMailInd":"N","HldMail":"","Typ":"","VipTyp":"","name1":"Mr","name2":"","CreateDt":"19092023","MemShpLnth":"124 YEARS 003 MONTHS","CurrAge":"032 YEARS 004 MONTHS","ServLnth":"","RemainServ":"","AvailChnl1":"","AvailChnl2":"","AvailChnl3":"","AvailChnl4":"","AvailChnl5":"","AvailChnl6":"","AvailChnl7":"","AvailChnl8":"","BioEnrollDt":"99999999","BioEnrollTime":"00:00:00","KYCFlag":"H","IdTyp":"0001","DOB":"22101991","TDNPFlag":"N","DNPExpryDt":"","NibbsBVN":"","Fac":"","Coll":[{"AcctNum":"10205781559","Stat":"DISC","ChqbkFlag":"","CardFlag":"","AcctFlagTyp":"L","ProdDescptn":"MoMo Instant Loan","CurCode2":"BWP","RelnshpWtAcct":"OWN","Bal":"601.40","OvrdrftAcctLmt":"500.00","AcctTyp":"5000","AcctSubTyp":"0555","ShrtName":"","InstNum":"002","TagStat":"","LonOdAmt":"500.00","ArrAcctAmt":"560.00","Dpd":"2","OdInd":"","HowLong":"0.46","IBAN":"","AcctBrch":"35","CreationDt":"19092023","Acctstat":"40","PurpCod":"27","SignMndt":"","SignDetail":"","SignatoryNum":"0"}]}}
I have tried using and javascript to make single object array and respond json but doesnot works.
How do I achieve the expected output?
2
Answers
you can do it in JavaScript – comments in the code
You can use a custom JSON Schema along with JSON Transform Mediator for this.
First Create a Local Entry with the JSON Schema like below.
Then in your API/Sequence add the following before responding back.