使用JOLT创建一个新数组

时间:2018-03-26 15:39:13

标签: json jolt

我正在尝试使用JOLT修改JSON输出,我一直在使用它来重命名/删除字段,直到现在。

我想创建一个现有2个数组的新对象作为元素。

input.json

[
  {
    "features": [
      {
        "featureId": 1,
        "feature": "feature"
      }
    ],
    "product": [
      {
        "id": 1,
        "name": "name"
      }
    ]
  }
]

当前规范json:

[{
    "operation": "shift",
    "spec": {
      "*": {
        "features": {
          "*": {
            "featureId": "[&3].&2.[&1].featureId",
            "feature": "[&3].&2.[&1].feature"
          }
        },
        "product": {
          "*": {
            "id": "[&3].&2.[&1].id",
            "name": "[&3].&2.[&1].name"
          }
        }
      }
    }
    }
  ]

预期产出:

[
  {
    "newarray": {
      "features": [
        {
          "featureId": 1,
          "feature": "feature"
        }
      ],
      "product": [
        {
          "id": 1,
          "name": "name"
        }
      ]
    }
  }
]

基本上,我想在新对象中移动现有的两个数组。提前谢谢!

1 个答案:

答案 0 :(得分:1)

规格

[
  {
    "operation": "shift",
    "spec": {
      "*": { // outer array index
        // match features and product which are lists
        // and copy those lists to the output
        "*": "[0].newarray.&"
      }
    }
  }
]