Flat JSON to Nested JSON -JOLT帮助

slwdgvem  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(182)

我有一个要求,包括记录计数作为一个标题。所以尝试了下面的JOLT,但它不工作
我正面临一个问题,转换一个非常复杂的JSON输入和输出的详细信息如下所示。
输入

[
  {
    "Location": "A",
    "Item": "X",
    "Planning_Month": "Jan",
    "Production_Plant": "Plant1",
    "GM_M_Load_Plan_Planned_Supply": 100,
    "Total_Count": 75
  },
  {
    "Location": "B",
    "Item": "X",
    "Planning_Month": "Jan",
    "Production_Plant": "Plant1",
    "GM_M_Load_Plan_Planned_Supply": 1001,
    "Total_Count": 75
  },
  {
    "Location": "C",
    "Item": "X",
    "Planning_Month": "Jan",
    "Production_Plant": "Plant1",
    "GM_M_Load_Plan_Planned_Supply": 1001,
    "Total_Count": 75
  }
]

Jolt I m Using

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Total_Count": "response.Total_Count",
        "Location": "message[&1].Location",
        "Item": "message[&1].Item",
        "Planning_Month": "message[&1].Planning_Month",
        "Production_Plant": "message[&1].Production Plant",
        "W_Load_Planned_Supply": "message[&1].W Load Planned Supply"
      }
    }
  }
]

预期输出

{
  "response": {
    "Total_Count": 75
  },
  "message": [
    {
      "Location": "A",
      "Item": "X",
      "Planning_Month": "Jan",
      "Production Plant": "Plant1"
    },
    {
      "Location": "B",
      "Item": "X",
      "Planning_Month": "Jan",
      "Production Plant": "Plant1"
    },
    {
      "Location": "C",
      "Item": "X",
      "Planning_Month": "Jan",
      "Production Plant": "Plant1"
    }
  ]
}

请帮助任何人谁是一个颠簸Maven,帮助我得到所需的输出。我想我卡在最后一步了

7fhtutme

7fhtutme1#

您可以再添加一个spec,其类型为cardinality,如下所示

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Total_Count": "response.&",
        "Location|Item|Planning_Month": "message[&1].&",
        "P*_P*": "message[&1].P&(0,1) P&(0,2)"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "response": {
        "Total_Count": "ONE"
      }
    }
  }
]

考虑到所有对象具有相同的Total_Count

相关问题