arrays - 如何在 SnapLogic 中将数组项转换为对象

标签 arrays object 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 Formatter将传入文档聚合为单个 JSON。然后使用二进制到文档快照,并将编码/解码设置为。之后,您可以解析内容并将其放在映射器中的任何字段名称下。

示例管道:

Sample pipeline

二进制到文档:

binary to document

最终映射器:

parsing json

输出:

output

注释

  • JSON 格式化程序中未更改任何配置
  • 二进制到文档快照中将编码/解码设置为非常重要
  • 解析内容,例如 - JSON.parse($content)

解决方案#2

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

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

示例管道

enter image description here

按 N 分组

enter image description here

输出

enter image description here

关于arrays - 如何在 SnapLogic 中将数组项转换为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60638631/

相关文章:

javascript - 如何在 JavaScript 中从数组中删除 null

javascript - 在 Javascript 中显示对象输出

java - 在没有框架的情况下管理 DI 对象

python - SnapLogic Python 读取和执行 SQL 文件

arrays - SnapLogic - 更改映射器中的数组元素

javascript - 显示文档内对象数组的数据

C++ 整数数组转换和操作

javascript - 使用纯 Javascript 将文本节点附加到 <li>

json - 在 parse.com 类中存储嵌套的 Json

etl - 什么是 Snaplogic?