Guest
So sortieren Sie ein verschachteltes Array von Objekten im Karate-Framework
Post
by Guest » 17 Jan 2025, 06:20
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
1737091238
Guest
Zuerst muss das Array [b]accountPeriodDetails[/b] nach [b]accountSystemID[/b] sortiert werden, und für jede [b]accountSystemID[/b] muss das Array [b]monthlySummary[/b] sortiert werden bis [b] paymentReportDate[/b] [code]`` `*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 } ] } ] } } [/code] [list] [*]def accountPeriodDetails = Response1.organization.sbfeInformation.accountPeriodDetails [*]print accountPeriodDetails < li>def sorted1 = karate.sort(accountPeriodDetails, x => x.accountSystemID) [*]print sorted1` `` [/list] [code] 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 [/code]