Json 使用Jolt更改目标字段
我有几个例子需要将映射字段转换为数组字段,这些字段有时嵌套在几层深的地方。这些是文档中唯一需要更改的字段,因此其他字段不需要对其执行任何类型的转换。我当前的方法是在每个级别复制未更改的字段,如下所示:Json 使用Jolt更改目标字段,json,jolt,Json,Jolt,我有几个例子需要将映射字段转换为数组字段,这些字段有时嵌套在几层深的地方。这些是文档中唯一需要更改的字段,因此其他字段不需要对其执行任何类型的转换。我当前的方法是在每个级别复制未更改的字段,如下所示: [ { "operation": "shift", "spec": { "agentsMetrics": { "metricsPerAgent": { "*": { "$": "agentsMetrics.
[
{
"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
}
}
}
}
}
}
我的输入如下所示:
[
{
"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为目标。是否有任何方法可以针对特定字段并自行操作它们,同时保留其他所有内容
否/不带班次/当前不带班次。注意:轮班操作是从输入复制到输出。这种方法似乎还没有完全测试或评估效率,但:
{
"operation": "shift",
"spec": {
// derived from https://stackoverflow.com/questions/40494231/re-parent-a-json-object-using-jolt#40513842
"*": {
"@": "&"
},
// any specific shifts go here
}
}