有人可以帮助获取所需格式的 joltspec。
输入请求:
{
"data": {
"testDetails": [
{
"contactId": "941",
"contactType": "DM"
},
{
"contactId": "1041",
"contactType": "CM"
}
]
}
}
预期输出:
{
"id": "test_details",
"list": [
{
"id": "contact_type",
"value": "DM,CM"
},
{
"id": "contact_id",
"value": "941,1041"
}
]
}
输入规范:
[
{
"operation": "shift",
"spec": {
"data": {
"#test_details": "Request.dataset.testDetails.param.[0].id",
"@testDetails": "Request.dataset.testDetails.param.[0].list"
}
}
}
]
如果我尝试这样做,我会得到与输入中相同的列表。我尝试过使用 shift 但无法使其获得预期的 id 值对。谁能帮忙解决这个问题
最佳答案
您可以通过使用 modify-overwrite-beta
操作来组合这些逗号分隔的值,并对其余部分应用 shift
,例如
[
{
"operation": "shift",
"spec": {
"data": {
"testDetails": {
"*": {
"*": "&"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "&.id",
"*": "&1.&"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"value": "=concat(@(1,0),',',@(1,1))"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"@(1,&.id)": "&.id",
"@(1,&.value)": "&.value"
}
}
},
{
"operation": "shift",
"spec": {
"#id": "test_details",
"*": "list"
}
}
]
关于java - Jolt Conversion 需要将对象列表转换为以逗号分隔的 id 值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66805158/