当对象之间的JSON数据结构不同时,如何使用Jolt获取属性

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

有谁在这种情况下如何编写 JOLT 变换: 输入:

[
{
    "id": "65cf06b62fadc0122dc30f29",
    "code": "H34.23.9-240216-0003",
    "applicant": {
      "eformId": "60d990f88e6893001e5a7b42",
      "userId": "6186433deee4513fe0d86efc",
      "data": {
        "birthday": "",
        "address": "Thôn Kon Năng Treang",
        "gender": 2,
        "nation": {
          "label": "Việt Nam",
          "value": "5f39f4a95224cf235e134c5c"
        },
        "ghiChu": "",
        "identityDate": "",
        "noiDung": "",
        "phoneNumber": "",
        "province": {
          "label": "Tỉnh Kon Tum",
          "value": "5def47c5f47614018c000062"
        },
        "identityNumber": "062195002130",
        "soBoHoSo": "1",
        "organization": "Y Thảo",
        "district": {
          "label": "Huyện Đắk Hà",
          "value": "5def47c5f47614018c001615"
        },
        "identityAgency": {},
        "fullname": "Y Thảo",
        "fax": "",
        "village": {
          "label": "Xã Đắk Ui",
          "value": "5def47c5f47614018c123509"
        },
        "email": ""
      }
    }
  },
{
    "id": "65cf24e3f21075472fe549c7",
    "code": "H34.6-240216-0032",
    "nationCode": "G22.99-240216-030023-H34",
    "applicant": {
      "eformId": "624bb547cdb7f7ec092bee16",
      "data": {
        "fullname": "CÔNG TY CỔ PHẦN VIEON",
        "province": {
          "label": "Thành phố Hồ Chí Minh",
          "value": "5def47c5f47614018c000079"
        },
        "district": {
          "label": "Quận 3",
          "value": "5def47c5f47614018c001770"
        },
        "village": {
          "label": "Phường Võ Thị Sáu",
          "value": "5def47c5f47614018c127139"
        },
        "phoneNumber": "02838241919",
        "fax": "02838241919",
        "mail": "[email protected]",
        "taxCode": "0314415573",
        "contact": "Hoàng Lê Huế An ",
        "contactPhoneNumber": "0385792805",
        "chonDoiTuong": 2,
        "hinhThucNop": 2,
        "ownerFullname": "CÔNG TY CỔ PHẦN VIEON",
        "identityNumber": "0314415573",
        "ownerIdentityNumber": "0314415573",
        "isOwnerDossier": true
      }
    }
  }
]

预期输出:

[
  {
    "id": "65cf06b62fadc0122dc30f29",
    "eformId": "60d990f88e6893001e5a7b42",
    "gender": 2,
    "fullname": "Y Thảo",
    "ownerFullname": "",
    "province_label": "Tỉnh Kon Tum"
  },
  {
    "id": "65cf24e3f21075472fe549c7",
    "eformId": "624bb547cdb7f7ec092bee16",
    "gender": null,
    "fullname": "CÔNG TY CỔ PHẦN VIEON",
    "ownerFullname": "CÔNG TY CỔ PHẦN VIEON",
    "province_label": "Thành phố Hồ Chí Minh"
  }
]
arrays json apache-nifi jolt
1个回答
0
投票

您应该在移位规范中循环遍历数组中的所有对象,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": { 
        "id": "[&1].&",
        "@applicant.eformId": "[&1].eformId",
        "@applicant.data.gender": "[&1].gender",
        "@applicant.data.fullname": "[&1].fullname",
        "@applicant.data.ownerFullname": "[&1].ownerFullname",
        "@applicant.data.province.label": "[&1].province_label"
      }
    }
  }
]

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