我有几个需要将地图字段转换为数组字段的情况,这些字段有时嵌套了几层。这些是文档中唯一需要更改的字段,因此其他字段不需要对其执行任何类型的转换。我目前的方法是复制每个级别的未更改字段,如下所示:
[
{
"operation": "shift",
"spec": {
"agentsMetrics": {
"metricsPerAgent": {
"*": {
"$": "agentsMetrics.metricsPerAgent[#2].agentId",
"@": "agentsMetrics.metricsPerAgent[#2].value"
}
},
"*": {
"@": "agentsMetrics.&"
}
},
"skillsMetricsPerAgent": {
"metricsPerSkill": {
"*": {
"$": "skillsMetricsPerAgent.metricsPerSkill[#2].skillId",
"metricsPerAgent": {
"*": {
"$": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].agentId",
"@": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].value"
}
},
"*": {
"@": "skillsMetricsPerAgent.metricsPerSkill[#3].&"
}
}
},
"*": {
"@": "skillsMetricsPerAgent.&"
}
}
}
}
]
我的输入如下所示:
{
"agentsMetrics": {
"metricsTotals": {
"connectedEngagements": 70,
"nonInteractiveTotalHandlingTime": 309,
"totalHandlingTime": 47696,
"totalNonInteractiveChats": 2,
"totalInteractiveChats": 73
},
"metricsPerAgent": {
"645355412": {
"connectedEngagements": 2,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 1718,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 2
},
"645366912": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 488,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
},
"skillsMetricsPerAgent": {
"metricsTotals": {
"connectedEngagements": 70,
"nonInteractiveTotalHandlingTime": 309,
"totalHandlingTime": 47696,
"totalNonInteractiveChats": 2,
"totalInteractiveChats": 73
},
"metricsPerSkill": {
"641431612": {
"metricsTotals": {
"connectedEngagements": 7,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 6377,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 8
},
"metricsPerAgent": {
"645355312": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 115,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
},
"645365512": {
"connectedEngagements": 0,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 766,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
},
"1218517512": {
"metricsTotals": {
"connectedEngagements": 2,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 1379,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 2
},
"metricsPerAgent": {
"645367512": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 571,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
},
"645378812": {
"connectedEngagements": 1,
"nonInteractiveTotalHandlingTime": 0,
"totalHandlingTime": 808,
"totalNonInteractiveChats": 0,
"totalInteractiveChats": 1
}
}
}
}
}
}
有什么方法可以针对特定字段并自行操作它们,同时保持其他所有内容不变?在这种情况下,我想针对 metricsPerAgent 和 metricsPerSkill。