我有一个JSON对象,其中我有一个键policyList,其值类型为数组。在policyList中,名为product的键下还有另一个数组。
这里我想改变amount的值,它位于数组product的每个对象中。
我可以改变它,但最后我只得到了amount的数组,因为我想要修改amount值的整个原始对象。
请参阅this link的数据在JSONata练习链接,我有数据和表达式,我写的。
JSON:
{
"admissionDate": "2023-10-04",
"claimCaseId": 123,
"claimCaseStatusDescp": "Waiting",
"claimTypeDescp": "Hospitalization",
"dischargeDate": "2023-10-20",
"hospital": "abc",
"policyList": [
{
"policyNo": "P1",
"product": [
{
"amount": 10243,
"claimDecision": "7",
"claimDecisionDescp": "Pending",
"productName": "Auto"
},
{
"amount": 1023,
"claimDecision": "7",
"claimDecisionDescp": "Pending",
"productName": "Mob"
},
{
"amount": 100000,
"claimDecision": "8",
"claimDecisionDescp": "Approved",
"productName": "PA"
}
]
}
],
"reasonCode": ""
}
字符串
我写的表达式是:
$map($.policyList.product.amount, function($amount) {
$formatNumber($amount,'#,###')
})
型
接下来的输出是:
[
"10,243",
"1,023",
"100,000"
]
型
预期输出为:
{
"admissionDate": "2023-10-04",
"claimCaseId": 123,
"claimCaseStatusDescp": "Waiting",
"claimTypeDescp": "Hospitalization",
"dischargeDate": "2023-10-20",
"hospital": "abc",
"policyList": [
{
"policyNo": "P1",
"product": [
{
"amount": "10,243",
"claimDecision": "7",
"claimDecisionDescp": "Pending",
"productName": "Auto"
},
{
"amount": "1,023",
"claimDecision": "7",
"claimDecisionDescp": "Pending",
"productName": "Mob"
},
{
"amount": "100,000",
"claimDecision": "8",
"claimDecisionDescp": "Approved",
"productName": "PA"
}
]
}
],
"reasonCode": ""
}
型
注意事项:在预期的输出中,我将amount显示为字符串,但我可以使用任何数据类型,因为我对值的操作在输出中存在
1条答案
按热度按时间wgx48brx1#
要就地更新嵌套对象,可以使用Transform操作符:
字符串
在Stedi Playground上查看。