如何在 Apache NiFi 中使用 Jolt 将 JSON 数组转换为嵌套结构?

问题描述 投票:0回答:1

我正在尝试使用 Apache NiFi 中的 Jolt 将 JSON 数据从输入结构转换为所需的输出结构。这是我输入的 JSON:

[
  {
    "LocationAvailabilitySync": {
      "TransactionNumber": "31ea1a10-abc4-4aa5-a8c6-6f204903073a",
      "TransactionType": "SyncDetail",
      "CurrentPage": 5,
      "CurrentCount": 15,
      "TotalCount": 9,
      "TotalPages": 9,
      "SyncCount": null,
      "ViewConfigurationName": null
    },
    "ItemId": "5678",
    "LocationId": "0088",
    "Status": "AVAILABLE",
    "ViewName": "ATC_1",
    "ViewId": "05fdb789-a372-4f0e-8e35-9517f3cf02cc",
    "Quantity": 567,
    "TransactionDateTime": "2020-04-29T18:35:56.662",
    "NextAvailabilityDate": null,
    "TotalIncludingSubstituteItems": 567,
    "SubstituteItemsAvailable": false,
    "SubstitutionDetail": null
  },
  {
    "LocationAvailabilitySync": {
      "TransactionNumber": "31ea1a10-abc4-4aa5-a8c6-6f204903073a",
      "TransactionType": "SyncDetail",
      "CurrentPage": 5,
      "CurrentCount": 15,
      "TotalCount": 9,
      "TotalPages": 9,
      "SyncCount": null,
      "ViewConfigurationName": null
    },
    "ItemId": "1234",
    "LocationId": "0088",
    "Status": "AVAILABLE",
    "ViewName": "ATC_1",
    "ViewId": "05fdb789-a372-4f0e-8e35-9517f3cf02cc",
    "Quantity": 567,
    "TransactionDateTime": "2020-04-29T18:35:56.662",
    "NextAvailabilityDate": null,
    "TotalIncludingSubstituteItems": 567,
    "SubstituteItemsAvailable": false,
    "SubstitutionDetail": null
  }
]

这是所需的输出 JSON:

{
  "LocationAvailabilitySync": [
    {
      "TransactionNumber": "31ea1a10-abc4-4aa5-a8c6-6f204903073a",
      "TransactionType": "SyncDetail",
      "CurrentPage": 5,
      "CurrentCount": 15,
      "TotalCount": 9,
      "TotalPages": 9,
      "SyncCount": null,
      "ViewConfigurationName": null,
      "LocationAvailabilityResponse": [
        {
          "ItemId": "5678",
          "LocationId": "0088",
          "Status": "AVAILABLE",
          "ViewName": "ATC_SOFKA1",
          "ViewId": "e88130a2-6a07-408b-8bf8-03e3d28cf057",
          "Quantity": 567,
          "TransactionDateTime": "2020-04-29T18:35:56.662",
          "NextAvailabilityDate": null,
          "TotalIncludingSubstituteItems": 567,
          "SubstituteItemsAvailable": false,
          "SubstitutionDetail": null
        },
        {
          "ItemId": "1234",
          "LocationId": "0088",
          "Status": "AVAILABLE",
          "ViewName": "ATC_SOFKA2",
          "ViewId": "e88130a2-6a07-408b-8bf8-03e3d28cf058",
          "Quantity": 567,
          "TransactionDateTime": "2020-04-29T18:35:56.662",
          "NextAvailabilityDate": null,
          "TotalIncludingSubstituteItems": 567,
          "SubstituteItemsAvailable": false,
          "SubstitutionDetail": null
        }
      ]
    }
  ]
}

我需要帮助创建 Jolt 规范来实现这一转变。任何人都可以提供可以实现此目的的指导或示例 Jolt 规范吗?

谢谢!

apache-nifi jolt
1个回答
0
投票

s您可以使用 cardinality 规范,以便从每个数组中仅选取一个组件,该数组是在组合

"LocationAvailabilitySync"
规范中嵌套的属性时形成的,例如 [ { "operation": "shift", "spec": { "*": { "LocationAvailabilitySync": { "*": "&1[0].&" }, "*": "LocationAvailabilitySync[0].LocationAvailabilityResponse[&1].&" } } }, { "operation": "cardinality", "spec": { "*": { "*": { "*": "ONE", "LocationAvailabilityResponse": "MANY" } } } } ]

	
© www.soinside.com 2019 - 2024. All rights reserved.