无法使用 JOLT JSON 库将 JSON 对象转换为对象数组

Unable to transform a JSON Object into Array of objects using JOLT JSON library

我必须转换的输入JSON如下:

{
  "Business": [
    {
      "Label": "Entertainment",
      "category": "Advert",
      "weight": "",
      "types": [
        "T1",
        "T2"
      ]
    },
    {
      "Label": "FMCG",
      "category": "Campaign",
      "weight": "",
      "types": [
        "T9",
        "T10"
      ]
    }
  ]
}

预期输出:

{
  "Business": [
    {
      "Label": "Entertainment",
      "category": "Advert",
      "weight": "",
      "types": "T1"
    },
    {
      "Label": "Entertainment",
      "category": "Advert",
      "weight": "",
      "types": "T2"
    },
    {
      "Label": "FMCG",
      "category": "Campaign",
      "weight": "",
      "types": "T9"
    },
    {
      "Label": "FMCG",
      "category": "Campaign",
      "weight": "",
      "types": "T10"
    }
  ]
}

我尝试了 JOLT github 帮助页面上提供的不同 JsonSpec。但我无法解决这个问题。任何帮助或指点将不胜感激。

您必须进行两次轮班操作。

您想 "duplicate" 标签和类别基于 "types" 数组中的条目数。所以首先这样做,进入临时 "bizArray".

同时在临时 "typeArray" 中记录哪个 "type" 与重复的标签和类别一起使用,它具有与 bizArray 相同的索引。

在第二个班次中,"join" 两个平行数组,"bizArray" 和 "typesArray" 得到你的最终数组。

规格

[
  {
    "operation": "shift",
    "spec": {
      "Business": {
        "*": { // business array
          "types": {
            "*": { // type array
              "@2": "bizArray[]",  // make a copy of the whole biz object
              "@": "typesArray[]"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "bizArray": {
        "*": { // bizArray index
          "Label": "Business[&1].Label",
          "category": "Business[&1].category",
          "weight": "Business[&1].weight"
        }
      },
      "typesArray": {
        "*": "Business[&].types"
      }
    }
  }
]