I am facing an issue while converting JSON to BadgerFish form. Error as below. I know something is wrong is for loop.
Any help in this is highly appreciated
"errorMessage": "Unable to convert JSON in 'badgerfish' format to XML", "errorCode": "0x85800092", "errorDescription": "Unable to convert JSON to XML. The input is not in the specified format.",
Code Snippet
let RepaymentAmount = {}
for (let el in reqBody.LoanRepaymentDetails) {
RepaymentAmount[el] = {$:reqBody.LoanRepaymentDetails[el]}
}
let bfReqBody = {
LoanPmtCalcInqRq: {
'LoanRepaymentDetails':{
RepaymentAmount,
},
},
}
let xmlReqBody = converter.toXML('badgerfish', bfReqBody)
Input JSON{{ "LoanRepaymentDetails": [{ "PaymentType": "com.anz.InterestPayment", "PmtTimeframe": { "RecurrenceRule": { "RecurrenceType": "MAR" } } }, { "PaymentType": "com.anz.PrincipalPayment", "PmtTimeframe": { "RecurrenceRule": { "RecurrenceType": "Monthly" } } }]}
Desired XML<LoanPmtCalcInqRq><LoanPmtCalcInqRq><LoanRepaymentDetails> <RepaymentAmount> <PaymentType>com.anz.InterestPayment</PaymentType> <PmtTimeframe> <RecurrenceRule> <RecurrenceType>MAR</RecurrenceType> </RecurrenceRule> </PmtTimeframe> </RepaymentAmount> <RepaymentAmount> <PaymentType>com.anz.PrincipalPayment</PaymentType> <PmtTimeframe> <RecurrenceRule> <RecurrenceType>Monthly</RecurrenceType> </RecurrenceRule> </PmtTimeframe> </RepaymentAmount> </LoanRepaymentDetails></LoanPmtCalcInqRq>
Desired BadgerFish
"LoanPmtCalcInqRq":{"LoanRepaymentDetails":{"RepaymentAmount":{"PaymentType":{"$":{"com.anz.InterestPayment"}}
"PmtTimeframe":{"RecurrenceRule":{"RecurrenceType":{$:"MAR"}}}},
"RepaymentAmount":{"PaymentType":{"$":{"com.anz.PrincipalPayment"}}
"PmtTimeframe":{"RecurrenceRule":{"RecurrenceType":{$:"Monthly"}}}}}
------------------------------
Varun Rao
------------------------------