3

对于学生项目,我必须提高数据质量。第一步是请求 API。其次,我们必须编辑 json 结构。

这是来自 API 的响应:

{
    "lists": [
        [
            0,
            451,
            "test",
            "953"
        ],
        [
            2,
            1010,
            "hello",
            "610"
        ]
    ]
}

现在使用 jolt 我想得到这样的结果:

{
  "lists": [
    {
      "id": 0,
      "clientId": 451,
      "name": "test",
      "custom_value": "953"
    },
    {
      "id": 2,
      "clientId": 1010,
      "name": "hello",
      "custom_value": "610"
    }
  ]
}

目前,我可以访问数据值,但我不知道如何将它分成带有对象的数组。

我的“代码”:

[
  {
    "operation": "shift",
    "spec": {
      "lists": {
        "*": {
          "*": {
            "*": {
              "$0": "lists"
            }
          }
        }
      }
    }
  }
]

我在哪里错了,如何正确编辑原始数组的结构?

4

1 回答 1

6

规格

[
  {
    "operation": "shift",
    "spec": {
      "lists": {
        "*": { // lists array
          "0": "lists[&1].id",
          "1": "lists[&1].clientId",
          "2": "lists[&1].name",
          "3": "lists[&1].custom_value"
        }
      }
    }
  }
]
于 2017-03-09T22:51:13.600 回答