3

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?

1 Answer 1

7

Spec

[
  {
    "operation": "shift",
    "spec": {
      "lists": {
        "*": { // lists array
          "0": "lists[&1].id",
          "1": "lists[&1].clientId",
          "2": "lists[&1].name",
          "3": "lists[&1].custom_value"
        }
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

1 Comment

So many thanks!! I spent so many time and the answer is really simple... You make my day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.