pacman
pacman

Reputation: 835

Convert two arrays into single array of objects

I have two arrays and need to convert these arrays into a single object array using jolt.

Input

"Name": ["Test  Test", "Test2  Test"]
"email": ["[email protected]", "[email protected]"]

output

[{"Name":"Test  Test","email":"[email protected]"},{"Name":"Test2  Test","email":"[email protected]"}]

Upvotes: 2

Views: 195

Answers (1)

Matthew Warman
Matthew Warman

Reputation: 3442

Description inline:

[
  {
    "operation": "shift",
    "spec": {
      // for every key
      "*": {
        // and every item in the array
        "*": {
          // create a structure <index of array> : key : value
          // This will therefore join the two because the indexes will be the same
          "@": "&.&2"
        }
      }
    }
  },
  {
    //Remove the index as key
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]

I'd suggest running the first shift to get understanding of the description.

Upvotes: 1

Related Questions