【问题标题】:Jolt Transform to append extracted dataJolt 转换以附加提取的数据
【发布时间】:2023-02-05 10:56:05
【问题描述】:

我是 Jolt Transform 的新手,有一些我想要转换的 EDI 数据。我想保留原始数据并附加一些提取的元素,以便下游流程更容易到达。这是一个示例:

输入

{
    "id": "2000",
    "segments": [
        {
            "REF02": "xxxxxxxxxxxx",
            "REF01": "0F",
            "id": "REF"
        },
        {
            "REF02": "yyyyyyyyyyyy",
            "REF01": "1L",
            "id": "REF"
        }
    ],
    "loops": [
        {
            "id": "2100",
            "segments": []
        },
        {
            "id": "2100",
            "segments": [],
            "loops": [
                {
                    "id": "2300",
                    "segments": [
                        {
                            "DTP01": "348",
                            "DTP03": "20220101",
                            "DTP02": "D8",
                            "id": "DTP"
                        },
                        {
                            "DTP01": "349",
                            "DTP03": "20221231",
                            "DTP02": "D8",
                            "id": "DTP"
                        }
                    ]
                }
            ]
        }
    ]
}

期望的输出

{
    "ext": {
        "subscriber": "xxxxxxxxxxxx",
        "start": "20220101"
    },
    "id": "2000",
    "segments": [
        {
            "REF02": "xxxxxxxxxxxx",
            "REF01": "0F",
            "id": "REF"
        },
        {
            "REF02": "yyyyyyyyyyyy",
            "REF01": "1L",
            "id": "REF"
        }
    ],
    "loops": [
        {
            "id": "2100",
            "segments": []
        },
        {
            "id": "2100",
            "segments": [],
            "loops": [
                {
                    "id": "2300",
                    "segments": [
                        {
                            "DTP01": "348",
                            "DTP03": "20220101",
                            "DTP02": "D8",
                            "id": "DTP"
                        },
                        {
                            "DTP01": "349",
                            "DTP03": "20221231",
                            "DTP02": "D8",
                            "id": "DTP"
                        }
                    ]
                }
            ]
        }
    ]
}

也就是说,我想附加 ext 元素 - 从原始元素复制值。

在 xpath 术语中,提取值的路径如下所示:

订户/segments[../id eq "2000"]/..[REF01 eq "0F"]/REF02/text()

开始(/loops[../id eq "2000"]/../segments[../id eq "2100"])[1]/..[id eq "NM1" and NM101 eq "IL"][DTP01 eq "348"]/DTP03/text()

谢谢您的帮助。

【问题讨论】:

    标签: jolt


    【解决方案1】:

    我最终得到了这个解决方案。如果有任何关于精简、更优雅的反馈,请告诉我。

    [
      {
        "operation": "default",
        "spec": {
          "dummy": {}
        }
      },
      {
        "operation": "shift",
        "spec": {
          "dummy": {
            "@2,segments": {
              "*": {
                "REF01": {
                  "0F": {
                    "@2,REF02": "ext.subscriber"
                  }
                }
              }
            },
            "@2,loops": {
              "*": {
                "id": {
                  "2100": {
                    "@2,loops": {
                      "*": {
                        "id": {
                          "2300": {
                            "@2,segments": {
                              "*": {
                                "DTP01": {
                                  "348": {
                                    "@2,DTP03": "ext.start"
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "id": "id",
          "segments": "segments",
          "loops": "loops"
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 1970-01-01
      相关资源
      最近更新 更多