简体   繁体   中英

JSON string array to object array using JOLT

For a student project I have to improve data quality. The first step is to request an API. Secondly, we have to edit the json structure.

This is the response from the API :

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

Now using jolt I want to have a result like that :

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

Currently, I can access to data values but I don't know how to separate it into array with objects.

My 'code' :

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

Where I'm wrong and how can I edit the structure of the original array properly?

Spec

[
  {
    "operation": "shift",
    "spec": {
      "lists": {
        "*": { // lists array
          "0": "lists[&1].id",
          "1": "lists[&1].clientId",
          "2": "lists[&1].name",
          "3": "lists[&1].custom_value"
        }
      }
    }
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM