【问题标题】:Jolt Transformer Grouping based on the fields inside the object基于对象内部字段的 Jolt Transformer 分组
【发布时间】:2023-02-21 21:19:17
【问题描述】:

我想根据字段 profileNameassetLevel1assetLevel2 对输入数组对象进行分组。

输入:

{
  "product": [
    {
      "id": "id1",
      "entity": "entity1",
      "productID": "productID1",
      "productName": "productName1",
      "unitPrice": "unitPrice1",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    },
    {
      "id": "id3",
      "entity": "entity3",
      "productID": "productID3",
      "productName": "productName3",
      "unitPrice": "unitPrice3",
      "assetLevel1": "Fixed Income",
      "assetLevel2": "Global Aggregate Funds",
      "profileName": "Novice Level"
    },
    {
      "id": "id2",
      "entity": "entity2",
      "productID": "productID2",
      "productName": "productName2",
      "unitPrice": "unitPrice2",
      "assetLevel1": "Equities",
      "assetLevel2": "US Large Cap Equity",
      "profileName": "Beginner Level"
    }
  ]
}

我目前的规格:

[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1[]"
      }
    }
  }
]

期望的输出:

{
  "Beginner Level": {
    "Equities": [
      {
        "US Large Cap Equity": [
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity1",
            "id": "id1",
            "productID": "productID1",
            "productName": "productName1",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice1"
          },
          {
            "assetLevel1": "Equities",
            "assetLevel2": "US Large Cap Equity",
            "entity": "entity2",
            "id": "id2",
            "productID": "productID2",
            "productName": "productName2",
            "profileName": "Beginner Level",
            "unitPrice": "unitPrice2"
          }
        ]
      }
    ]
  },
  "Novice Level": {
    "Fixed Income": [
      {
        "Global Aggregate Funds": [
          {
            "assetLevel1": "Fixed Income",
            "assetLevel2": "Global Aggregate Funds",
            "entity": "entity3",
            "id": "id3",
            "productID": "productID3",
            "productName": "productName3",
            "profileName": "Novice Level",
            "unitPrice": "unitPrice3"
          }
        ]
      }
    ]
  }
}

谁能帮忙?

我已经尝试了上述方法但无法继续,因为我是这方面的新手。

【问题讨论】:

  • 你在 Equities 中有 Global Aggregate Funds。但是他们的对象是US Large Cap Equity。看来您想要的输出是错误的。如果不是,请说明它们之间的关系。
  • 感谢您的反馈,更正了文本,因为它是复制粘贴的结果。

标签: json transform jolt transformer-model


【解决方案1】:

您可以使用此规范:

[
  {
    "operation": "shift",
    "spec": {
      "product": {
        "*": "@profileName.@assetLevel1.@assetLevel2[]"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": "MANY"
      }
    }
  }
]

【讨论】:

  • 你是上帝派来的兄弟。谢谢你!
猜你喜欢
  • 2020-12-11
  • 1970-01-01
  • 2019-05-06
  • 2023-02-13
  • 1970-01-01
  • 2023-01-16
  • 2020-05-22
  • 1970-01-01
  • 2013-03-27
相关资源
最近更新 更多