需要 JOLT 规范将源 JSON 格式转换为所需的 JSON 格式
need JOLT spec to transform source JSON format to desired JSON format
输入JSON如下
[
{
“correlationId”:“12345”,
"payloadFormat": "金钱",
“有效载荷”:{
"DE61": "000001000150084063368",
“位置”:“南”,
"name": "达拉斯",
“流行”:“2M”
}
},
{
“correlationId”:“ed1e3”,
"payloadFormat": "现金",
“有效载荷”:{
"DE": "000001000150084063368",
“位置”:“西”,
"name": "洛杉矶",
“流行”:“4M”
}
}
]
需要转换成如下输出信息。
[
{
"payload": {
"correlationId": "12345",
"payloadFormat": "Money",
"DE61SF1": "00",
"DE61SF2": "100015008",
"DE61SF3": "4063368",
"location": "south",
"name": "Dallas",
"pop": "2M"
}
},
{
"payload": {
"correlationId": "ed1e3",
"payloadFormat": "Cash",
"DE61SF1": "00",
"DE61SF2": "100015008",
"DE61SF3": "4063368",
"location": "west",
"name": "LosAngeles",
"pop": "4M"
}
}
]
检查此规范,
[
{
"operation": "shift",
"spec": {
"*": {
"@": "&",
// Shift all the DE nodes to a same named node.
// Here it is moved as TMPDE
"payload": {
"DE|DE61": "&2.payload.TMPDE"
}
}
}
}, {
"operation": "modify-default-beta",
"spec": {
"*": {
"payload": {
"DE61SF1": "=substring(@(1,TMPDE), 2, 4)",
"DE61SF2": "=substring(@(1,TMPDE), 5, 14)",
"DE61SF3": "=substring(@(1,TMPDE), 14, 21)"
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"correlationId": "[&1].payload.correlationId",
"payloadFormat": "[&1].payload.payloadFormat",
"payload": {
"DE61SF1": "[&2].payload.DE61SF1",
"DE61SF2": "[&2].payload.DE61SF2",
"DE61SF3": "[&2].payload.DE61SF3",
"location": "[&2].payload.location",
"pop": "[&2].payload.pop",
"name": "[&2].payload.name"
}
}
}
}
]
输入JSON如下 [ { “correlationId”:“12345”, "payloadFormat": "金钱", “有效载荷”:{ "DE61": "000001000150084063368", “位置”:“南”, "name": "达拉斯", “流行”:“2M” } }, { “correlationId”:“ed1e3”, "payloadFormat": "现金", “有效载荷”:{ "DE": "000001000150084063368", “位置”:“西”, "name": "洛杉矶", “流行”:“4M” } } ]
需要转换成如下输出信息。
[ {
"payload": {
"correlationId": "12345",
"payloadFormat": "Money",
"DE61SF1": "00",
"DE61SF2": "100015008",
"DE61SF3": "4063368",
"location": "south",
"name": "Dallas",
"pop": "2M"
}
}, {
"payload": {
"correlationId": "ed1e3",
"payloadFormat": "Cash",
"DE61SF1": "00",
"DE61SF2": "100015008",
"DE61SF3": "4063368",
"location": "west",
"name": "LosAngeles",
"pop": "4M"
}
} ]
检查此规范,
[
{
"operation": "shift",
"spec": {
"*": {
"@": "&",
// Shift all the DE nodes to a same named node.
// Here it is moved as TMPDE
"payload": {
"DE|DE61": "&2.payload.TMPDE"
}
}
}
}, {
"operation": "modify-default-beta",
"spec": {
"*": {
"payload": {
"DE61SF1": "=substring(@(1,TMPDE), 2, 4)",
"DE61SF2": "=substring(@(1,TMPDE), 5, 14)",
"DE61SF3": "=substring(@(1,TMPDE), 14, 21)"
}
}
}
}, {
"operation": "shift",
"spec": {
"*": {
"correlationId": "[&1].payload.correlationId",
"payloadFormat": "[&1].payload.payloadFormat",
"payload": {
"DE61SF1": "[&2].payload.DE61SF1",
"DE61SF2": "[&2].payload.DE61SF2",
"DE61SF3": "[&2].payload.DE61SF3",
"location": "[&2].payload.location",
"pop": "[&2].payload.pop",
"name": "[&2].payload.name"
}
}
}
}
]