将Json转换为Joson转换为Flat Json

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

我与这个人非常接近。但是,恐怕输出的内容并非我想要的。有人可以帮我纠正我的Jolt Spec以获得我想要的确切转换吗?我真的很想尽办法,对此我将不胜感激。

所以目前我的状态如下:

{
  "Hdr": {
    "DataSupplier": "BANK19000001",
    "FeedType": "Reuse",
    "SchemaVersion": "05.00",
    "SeqNo": "1",
    "DateProduced": "2019-09-30T11:44:12Z",
    "RecordCount": 1
  },
  "Data": [
    {
      "IM_SubmitterID": "BANK19000001",
      "IM_ParticipantID": "BANK19000001",
      "IM_AsOfDateTime": "2019-09-30T11:44:12Z",
      "IM_RepCpCodeType": "LEI",
      "CP_RepCp": "549300LW9VUUMJV5HC31",
      "CO_ActionType": "Normal",
      "CP_EntResponsibleForRep": "549300LW9VUUMJV5HC31",
      "LN_EventDate": "2019-09-30",
      "Clltrl": [
        {
          "CO_TypeOfCollComponent": "SECU",
          "CO_IdOfASecUsedAsColl": "FR0000131104",
          "RU_ValueOfReusedColl": "1000000",
          "RU_EstimatedReuseOfColl": "500000",
          "RU_ReusedCollCcy": "EUR"
        },
        {
          "CO_TypeOfCollComponent": "SECU",
          "CO_IdOfASecUsedAsColl": "FR0000131105",
          "RU_ValueOfReusedColl": "2000000",
          "RU_EstimatedReuseOfColl": "400000",
          "RU_ReusedCollCcy": "EUR"
        },
        {
          "CO_TypeOfCollComponent": "SECU",
          "CO_IdOfASecUsedAsColl": "FR0000131106",
          "RU_ValueOfReusedColl": "1500000",
          "RU_EstimatedReuseOfColl": "1000000",
          "RU_ReusedCollCcy": "EUR"
        },
        {
          "CO_TypeOfCollComponent": "CASH",
          "RU_ReinvestmentRate": "1.003",
          "RU_TypeOfReinvestedCashInvstmnt": "MMFT",
          "RU_ReinvestedCashAmt": "150000000",
          "RU_ReinvestedCashCcy": "USD"
        },
        {
          "CO_TypeOfCollComponent": "CASH",
          "RU_ReinvestmentRate": "0.05",
          "RU_TypeOfReinvestedCashInvstmnt": "REPM",
          "RU_ReinvestedCashAmt": "200000000",
          "RU_ReinvestedCashCcy": "EUR"
        }
      ],
      "FndngSrce": [
        {
          "RU_FundingSources": "OTHR",
          "RU_MarketValueOfTheFundingSources": "12000000",
          "RU_FundingSourcesCcy": "USD"
        },
        {
          "RU_FundingSources": "BSHS",
          "RU_MarketValueOfTheFundingSources": "150000000",
          "RU_FundingSourcesCcy": "EUR"
        }
      ],
      "UsrDfnd": {
        "IM_UserDefined1": "Test Data"
      }
    }
  ]
}

这是我目前为止编写的当前Jolt Specs(已编辑):

    [
  {
    "operation": "shift",
    "spec": {
      "Hdr": {
        "*": "header.&"
      },
      "Data": {
        "*": {
          "*": "data.&",
          "Clltrl": {
            "*": {
              "*": "data.&"
            },
            "UsrDfnd": {
              "*": "data.&"
            }
          }
        }
      }
    }
  }
]

以及转换后的输出:

{
  "header" : {
    "DataSupplier" : "BANK19000001",
    "FeedType" : "Reuse",
    "SchemaVersion" : "05.00",
    "SeqNo" : "1",
    "DateProduced" : "2019-09-30T11:44:12Z",
    "RecordCount" : 1
  },
  "body" : {
    "CO_TypeOfCollComponent" : [ "SECU", "SECU", "SECU", "CASH", "CASH" ],
    "CO_IdOfASecUsedAsColl" : [ "FR0000131104", "FR0000131105", "FR0000131106" ],
    "RU_ValueOfReusedColl" : [ "1000000", "2000000", "1500000" ],
    "RU_EstimatedReuseOfColl" : [ "500000", "400000", "1000000" ],
    "RU_ReusedCollCcy" : [ "EUR", "EUR", "EUR" ],
    "RU_ReinvestmentRate" : [ "1.003", "0.05" ],
    "RU_TypeOfReinvestedCashInvstmnt" : [ "MMFT", "REPM" ],
    "RU_ReinvestedCashAmt" : [ "150000000", "200000000" ],
    "RU_ReinvestedCashCcy" : [ "USD", "EUR" ],
    "RU_FundingSources" : [ "OTHR", "BSHS" ],
    "RU_MarketValueOfTheFundingSources" : [ "12000000", "150000000" ],
    "RU_FundingSourcesCcy" : [ "USD", "EUR" ],
    "Test Data" : null
  }
}

这确实接近期望的结果。但是,它缺少输入的“数据”部分中的某些数据。我实际上尝试了所有可能的组合,并尝试在线搜索答案,但无济于事。

所需的Json输出:

{
  "header" : {
    "DataSupplier" : "BANK19000001",
    "FeedType" : "Reuse",
    "SchemaVersion" : "05.00",
    "SeqNo" : "1",
    "DateProduced" : "2019-09-30T11:44:12Z",
    "RecordCount" : 1
  },
  "body" : {
    "IM_SubmitterID" : "BANK19000001",
    "IM_ParticipantID" : "BANK19000001",
    "IM_AsOfDateTime" : "2019-09-30T11:44:12Z",
    "IM_RepCpCodeType" : "LEI",
    "CP_RepCp" : "549300LW9VUUMJV5HC31",
    "CO_ActionType" : "Normal",
    "CP_EntResponsibleForRep" : "549300LW9VUUMJV5HC31",
    "LN_EventDate" : "2019-09-30",
    "CO_TypeOfCollComponent" : [ "SECU", "SECU", "SECU", "CASH", "CASH" ],
    "CO_IdOfASecUsedAsColl" : [ "FR0000131104", "FR0000131105", "FR0000131106" ],
    "RU_ValueOfReusedColl" : [ "1000000", "2000000", "1500000" ],
    "RU_EstimatedReuseOfColl" : [ "500000", "400000", "1000000" ],
    "RU_ReusedCollCcy" : [ "EUR", "EUR", "EUR" ],
    "RU_ReinvestmentRate" : [ "1.003", "0.05" ],
    "RU_TypeOfReinvestedCashInvstmnt" : [ "MMFT", "REPM" ],
    "RU_ReinvestedCashAmt" : [ "150000000", "200000000" ],
    "RU_ReinvestedCashCcy" : [ "USD", "EUR" ],
    "RU_FundingSources" : [ "OTHR", "BSHS" ],
    "RU_MarketValueOfTheFundingSources" : [ "12000000", "150000000" ],
    "RU_FundingSourcesCcy" : [ "USD", "EUR" ],
    "IM_UserDefined1" : "Test Data"
  }
}

有人可以帮我修改我的Jolt Specs以获得期望的结果。

非常感谢您的帮助。

json apache-nifi jolt
1个回答
1
投票

由于您没有提供输入数据的软拷贝,因此我无法使用您自己的数据进行测试。但是,我组成了以下逻辑等效项。假设我们有输入:

{
  "hdr": {
    "a": "a"
  },
  "dta": {
    "b": "b",
    "c": [
      {
        "d": "d1",
        "e": "e1"
      },
      {
        "d": "d2",
        "e": "e2"
      }
    ]
  }
}

并且我们想要的输出是:

{
  "header" : {
    "a" : "a"
  },
  "data" : {
    "b" : "b",
    "d" : [ "d1", "d2" ],
    "e" : [ "e1", "e2" ]
  }
}

然后以下内容可以用作震动规格:

[
  {
    "operation": "shift",
    "spec": {
      "hdr": {
        "*": "header.&"
      },
      "dta": {
        "*": "data.&",
        "c": {
          "*": {
            "*": "data.&"
          }
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.