Json Jolt spec将元素数组转换为具有ID的对象

Json Jolt spec将元素数组转换为具有ID的对象,json,apache-nifi,jolt,Json,Apache Nifi,Jolt,Jolt对我来说是新事物,我一直在努力解决这个问题,直到我写这篇文章为止 我想把这个转变为: { "Properties": [{ "Id": "property1", "Values": ["randomValue1", "randomValue2"] }, { "Id": "pro

Jolt对我来说是新事物,我一直在努力解决这个问题,直到我写这篇文章为止

我想把这个转变为:

{
    "Properties": [{
        "Id": "property1",
        "Values": ["randomValue1", "randomValue2"]
    }, {
        "Id": "property2",
        "Values": "randomValue3"
    }, {
        "Id": "property3",
        "Values": "randomValue4"
    }]
}
进入这个

{
    "Properties": [{
        "Id": "property1",
        "Values": "randomValue1"
    },{
        "Id": "property1",
        "Values": "randomValue2"
    }, {
        "Id": "property2",
        "Values": "randomValue3"
    }, {
        "Id": "property3",
        "Values": "randomValue4"
    }]
}
每个属性的值可以是1个值,也可以是未知数量值的数组

我已将以下json更改为第一个json中的内容:

{
    "Properties": {
        "property1": ["randomValue1", "randomValue1"],
        "property2": ["randomValue3"],
        "property3": ["randomValue4"]
    }
}
规格:

RHS上的属性名称是通用的,属性值的数量也可以不同。 提前感谢您抽出时间帮助我。

检查这是否有帮助:

[
  {
    "operation": "cardinality",
    "spec": {
      "Properties": {
        "*": {
          // normalize values to always be a list
          "Values": "MANY"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Properties": {
        "*": {
          "Values": {
            "*": {
              // create arrays with values and ids
              "@": "Values",
              "@(2,Id)": "Id"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Values": {
        "*": {
          // create the final list joining ids and values at the indexes you want
          "@": "Properties[&1].Values",
          "@(2,Id[#1])": "Properties[&1].Id"
        }
      }
    }
  }
]
检查这是否有帮助:

[
  {
    "operation": "cardinality",
    "spec": {
      "Properties": {
        "*": {
          // normalize values to always be a list
          "Values": "MANY"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Properties": {
        "*": {
          "Values": {
            "*": {
              // create arrays with values and ids
              "@": "Values",
              "@(2,Id)": "Id"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Values": {
        "*": {
          // create the final list joining ids and values at the indexes you want
          "@": "Properties[&1].Values",
          "@(2,Id[#1])": "Properties[&1].Id"
        }
      }
    }
  }
]