在JSON输入中,我有时会得到数组,有时会得到没有数组标签的单个对象。如何使用Jolt转换转换JSON,并将这两个场景作为输入
不带数组的JSON:
{
"eventMetadata": {
"eventType": "Insert",
"baseObjectUid": "BASE_OBJECT",
"orsId": "orcl-TCR_HUB",
"triggerUid": "MESSAGE_QUEUE_RULE",
"messageId": "300894188",
"messageDate": "2023-08-30T23:54:32.335Z"
},
"insertEvent": {
"sourceSystemName": "R12",
"sourceKey": "XXXXX",
"eventDate": "2023-08-30T23:54:32.335Z",
"rowid": "9800029",
"xrefKey": {
"systemName": "R12",
"sourceKey": "XXXXX"
}
}
}
应为JSON first非空非null:
{
"systemName": "R12",
}
JSON with array:
{
"eventMetadata": {
"eventType": "Insert",
"baseObjectUid": "BASE_OBJECT",
"orsId": "orcl-TCR_HUB",
"triggerUid": "MESSAGE_QUEUE_RULE",
"messageId": "300894188",
"messageDate": "2023-08-30T23:54:32.335Z"
},
"insertEvent": [
{
"sourceSystemName": "R12",
"sourceKey": "XXXXX",
"eventDate": "2023-08-30T23:54:32.335Z",
"rowid": "9800029",
"xrefKey": {
"systemName": "",
"sourceKey": "XXXXX"
}
},
{
"sourceSystemName": "R12",
"sourceKey": "XXXXX",
"eventDate": "2023-08-30T23:54:32.335Z",
"rowid": "9800029",
"xrefKey": {
"systemName": "R12",
"sourceKey": "XXXXX"
}
},
{
"sourceSystemName": "R12",
"sourceKey": "XXXXX",
"eventDate": "2023-08-30T23:54:32.335Z",
"rowid": "9800029",
"xrefKey": {
"systemName": "Y12",
"sourceKey": "XXXXX"
}
}
]
}
预期输出JSON first非空非null值:
{
"systemName": "R12"
}
1条答案
按热度按时间lkaoscv71#
您可以使用以下转换