James Mark
James Mark

Reputation: 349

Create "key - value" pair json from the list of given json values using JOLT

I have scenario where the json is just with list of string in an array without key but i would like to add key to each string using jolt transformation. Its something weird usecase and could not find out much information to solve this.

Source json:

[
  [
    "John",
    "200.01"
  ],
  [
    "David",
    "500.00"
  ]
]

Expected outcome:

[
  {
    "name": "John",
    "amount": "200.01"
  },
  {
    "name": "David",
    "amount": "500.00"
  }
]

Thank you for helping me on this and it would be really appreciated!..

Upvotes: 0

Views: 155

Answers (1)

Jagadesh
Jagadesh

Reputation: 2116

This spec works

For the String array the Objects can be shifted only by using index.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "0": "[#2].name",
        "1": "[#2].amount"
      }
    }
  }
]

Upvotes: 1

Related Questions