我正在尝试编写一个jolt规范来转换输入JSON。我有以下输入:
[{
"id": "11500887",
"created": "2023-03-16T18:34:24.485+0200",
"items": [{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "10000",
"fromString": "In Definition",
"to": "1",
"toString": "Open"
}]
}, {
"id": "11500905",
"created": "2023-03-16T18:35:05.552+0200",
"items": [{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "1",
"fromString": "Open",
"to": "10001",
"toString": "Committed"
}]
}, {
"id": "11500907",
"created": "2023-03-16T18:35:11.634+0200",
"items": [{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "10001",
"fromString": "Committed",
"to": "3",
"toString": "In Progress"
}]
}, {
"id": "12223186",
"created": "2023-05-03T00:55:00.323+0300",
"items": [{
"field": "resolution",
"fieldtype": "jira",
"fieldId": "resolution",
"from": null,
"fromString": null,
"to": "10008",
"toString": "Done"
}, {
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "10018",
"toString": "In Testing"
}]
}]
jolt变换后的预期输出为:
[{
"date": "2023-03-16T18:34:24.485+0200",
"field": "status",
"from": "In Definition",
"to": "Open"
}, {
"date": "2023-03-16T18:35:05.552+0200",
"field": "status",
"from": "Open",
"to": "Committed"
}, {
"date": "2023-03-16T18:35:11.634+0200",
"field": "status",
"from": "Committed",
"to": "In Progress"
}, {
"date": "2023-05-03T00:55:00.323+0300",
"field": "status",
"from": "In Progress",
"to": "Testing"
}]
以下是我目前的spec:
[
{
"operation": "shift",
"spec": {
"*": {
"items": {
"*": {
"@2,created": "[&3].date",
"field": "[&3].field",
"fromString": "[&3].from",
"toString": "[&3].to"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"field": {
"status": {
"@2": "tmp.[]"
}
}
}
}
},
{
"operation": "default",
"spec": {
"tmp": []
}
},
{
"operation": "shift",
"spec": {
"tmp": [""]
}
}
]
我很接近了,但是我丢失了最后一个状态更改,因为它被嵌入到一个数组中,并且我的spec只在数组中有一个项目时才起作用。
有什么建议吗?
3条答案
按热度按时间1qczuiv01#
你应该稍微改变一下你的规格。如以下JOLT规范:
dddzy1tm2#
技术参数
anauzrmj3#