0

I work on a project where the output of one of our APIs is a JSON array. I'd like to encapsulate this array inside an object.

I try to use a JOLT transformation (this is the first time I use this tool) to achieve this. I've already searched through a lot of example, but I still can't figure out what my JOLT specification has to be to perform the transformation. I can't find what I am looking for.

For example, if my input is like this:

[
  {
    "id": 1,
    "name": "foo"
  },
  {
    "id": 2,
    "name": "bar"
  }
]

I'd like the output to be:

{
  "list":
  [
    {
      "id": 1,
      "name": "foo"
    },
    {
      "id": 2,
      "name": "bar"
    }
  ]
}

In short, I just want to put my array inside a field of another object.

1 Answer 1

1

You can use a shift transformation spec such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "list[]"
    }
  }
]

where "*" wildcard represents indices of the current wrapper array of objects

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. This is exactly what I was looking for. I was expecting something way more complicated.
You're welcome @Ctorres , best wishes!

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.