如何将数组项转换为 SnapLogic 中的对象

How do I turn array items into an object in SnapLogic

在 SnapLogic 中,我有一个像下面这样的输入 JSON,它看起来是一个数组。我试图将它放入一个结构中,其中它是一个名为 "remitLocations" 的对象,由包含以下项目的地址数组组成。我一直在尝试使用映射器和结构快照来执行此操作。我还尝试使用 JSON 和 XML 生成器来为其提供我想要的结构,但到目前为止没有任何效果。

[
  {
    "addressInternalid": 2631363,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "5309 GREENWAY",
    "address2": "5301 REDWAY",
    "address3": "5504 BLUEWAY",
    "poBox": "0912KHJWD",
    "country": "USA",
    "state": "US-TX",
    "city": "FREE",
    "zip": "78211",
    "phone": "2229808888",
    "phoneExtn": "091",
    "fax": "747",
    "faxExtn": "737",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  },
  {
    "addressInternalid": 2631367,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "11305 4 PTS DR",
    "address2": "BLDG 2,#100",
    "country": "USA",
    "state": "US-TX",
    "city": "AUSTIN",
    "zip": "78726",
    "phone": "5126648805",
    "phoneExtn": "123",
    "fax": "123",
    "faxExtn": "134",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  },
  {
    "addressInternalid": 2631368,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "REMIT 11305 4 PTS DR",
    "address2": "BLDG 3",
    "country": "USA",
    "state": "US-TX",
    "city": "AUSTIN",
    "zip": "78725",
    "phone": "5126600000",
    "phoneExtn": "678",
    "fax": "678",
    "faxExtn": "678",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  }
]

注:答案包含两种解法。底部的似乎是更好的解决方案,因为您只使用了一个快照。


解决方案 #1

使用JSON格式化程序将传入的文档聚合成一个JSON。然后使用 Binary to Document Snap 并将 encoding/decoding 设置为 None。之后,你可以解析内容并将其放在映射器中的任何字段名称下。

示例管道:

二进制文件:

最终映射器:

输出:

备注

  • JSON格式化程序
  • 中没有更改任何配置
  • 将 encoding/decoding 设置为 NoneBinary to Document Snap 很重要
  • 像这样解析内容 - JSON.parse($content)

解决方案 #2

实际上有一个更好的方法 - 使用“Group By N Snap with Target Field as remitLocations 组大小 0

A value of 0 instructs the Snap to group all input documents into a single document.

示例管道

按 N 分组

输出