Page 1 of 1

So sortieren Sie ein verschachteltes Array von Objekten im Karate-Framework

Posted: 17 Jan 2025, 06:20
by Guest
Zuerst muss das Array accountPeriodDetails nach accountSystemID sortiert werden, und für jede accountSystemID muss das Array monthlySummary sortiert werden bis paymentReportDate

Code: Select all

``
`*def response =
'''
{
"organization": {
"accountPeriodDetails": [
{
"summaryPeriod": "P25M",
"accountSystemID": "2",
"tokenizedAccountNumber": "1X68MG14Z7Y5POID",
"monthlySummary": [
{
"paymentReportDate": "2023-09-17",
"accountTypeCode": "3",
"currentCreditLineAmount": null,
"mostRecentPaymentAmount": 7000,
"currentBalanceAmount": 63198,
"scheduledPaymentAmount": 0,
"newChargesAmount": null,
"totalPastDueAmount": 0
},
{
"paymentReportDate": "2023-08-17",
"accountTypeCode": "3",
"currentCreditLineAmount": null,
"mostRecentPaymentAmount": 10000,
"currentBalanceAmount": 56522,
"scheduledPaymentAmount": 0,
"newChargesAmount": null,
"totalPastDueAmount": 0
}
]
},
{
"summaryPeriod": "P25M",
"accountSystemID": "3",
"tokenizedAccountNumber": "MP3GOU0VQC4V5QQ0Z9GZVQUZNKH",
"monthlySummary": [
{
"paymentReportDate": "2024-10-31",
"accountTypeCode": "2",
"currentCreditLineAmount": 100000,
"mostRecentPaymentAmount": 100,
"currentBalanceAmount": 76035,
"scheduledPaymentAmount": null,
"newChargesAmount": null,
"totalPastDueAmount": 0
},
{
"paymentReportDate": "2024-04-30",
"accountTypeCode": "2",
"currentCreditLineAmount": 100000,
"mostRecentPaymentAmount": 432,
"currentBalanceAmount": 40135,
"scheduledPaymentAmount": null,
"newChargesAmount": null,
"totalPastDueAmount": 0
}
]
}
]
}
}
  • def accountPeriodDetails = Response1.organization.sbfeInformation.accountPeriodDetails
  • print accountPeriodDetails
    < li>def sorted1 = karate.sort(accountPeriodDetails, x => x.accountSystemID)
  • print sorted1`
    ``

Code: Select all

I have tried to sort using karate.sort(accountPeriodDetails, x => x.accountSystemID), getting error
:1:36 Expected ,** but found =>**
karate.sort(accountPeriodDetails, x => x.accountSystemID)

Any javascript function solution will also be helpful