我有以下输入 JSON,我想在 if 条件内添加 for 循环
[
{
"sports": {
"feeType": [
{
"sport_fee_type": "Discounted fee",
"sport_fee_total": 44730.77,
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket"
},
{
"total": 6187.79,
"sports_catagory": "Football"
}
]
},
{
"sport_fee_type": "Recurring fee",
"sport_fee_total": 44730.77,
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket"
},
{
"total": 6187.79,
"sports_catagory": "Football"
}
]
},
{
"sport_fee_type": "Non Recurring fee",
"sport_fee_total": 44730.77,
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket"
},
{
"total": 6187.79,
"sports_catagory": "Football"
}
]
}
]
}
}
]
[
{
"operation": "shift",
"spec": {
"*": {
"@sports": {
"@feeType": {
"*": {
"@sport_fee_type": {
"Discounted fee": {
"@fee_details": {
"*": {
"@total": "billing.feeSummary[#4].sportsCategories.amount",
// Expecting Sports catagory in upper case
"@sports_catagory": "billing.feeSummary[#4].sportsCategories.sportType"
}
},
"#DISCOUNTED": "billing.feeSummary[#4].type"
},
"Non Recurring fee": {
"@fee_details": {
"*": {
"@total": "billing.feeSummary[#4].sportsCategories.amount",
// Expecting Sports catagory in upper case
"@sports_catagory": "billing.feeSummary[#4].sportsCategories.sportType"
}
},
"#NON_RECURRING": "billing.feeSummary[#4].type"
},
"Recurring fee": {
"@fee_details": {
"*": {
"@total": "billing.feeSummary[#4].sportsCategories.amount",
// Expecting Sports catagory in upper case
"@sports_catagory": "billing.feeSummary[#4].sportsCategories.sportType"
}
},
"#RECURRING": "billing.feeSummary[#4].type"
}
}
}
}
}
}
}
}]
{
"billing": {
"feeSummary": [
{
"feeType": "RECURRING",
"sportsCategories": [
{
"sportType": "CRICKET",
"amount": 1117.3
},
{
"sportType": "FOOTBALL",
"amount": 6187.79
}
]
},
{
"feeType": "NON_RECURRING",
"sportsCategories": [
{
"sportType": "CRICKET",
"amount": 1117.3
},
{
"sportType": "FOOTBALL",
"amount": 6187.79
}
]
},
{
"feeType": "DISCOUNTED",
"sportsCategories": [
{
"sportType": "CRICKET",
"amount": 1117.3
},
{
"sportType": "FOOTBALL",
"amount": 6187.79
}
]
}
]
}
}
您可以考虑使用数组节点通过 [&5] 和 [&1] 标识符循环遍历它们,例如
[
{
"operation": "shift",
"spec": {
"*": {
"@sports.feeType": {
"*": {
"sport_fee_type": {
"Discounted fee": {
"@2,fee_details": {
"*": {
"total": "billing.feeSummary[&5].sportsCategories[&1].amount",
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#DISCOUNTED": "billing.feeSummary[#2].feeType"
},
"Non Recurring fee": {
"@2,fee_details": {
"*": {
"total": "billing.feeSummary[&5].sportsCategories[&1].amount",
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#NON_RECURRING": "billing.feeSummary[#4].feeType"
},
"Recurring fee": {
"@2,fee_details": {
"*": {
"total": "billing.feeSummary[&5].sportsCategories[&1].amount",
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#RECURRING": "billing.feeSummary[#4].feeType"
}
}
}
}
}
}
},
{ // convert the values of sportType attributes to uppercase
"operation": "modify-overwrite-beta",
"spec": {
"billing": {
"feeSummary": {
"*": {
"sportsCategories": {
"*": {
"sportType": "=toUpper"
}
}
}
}
}
}
}
]