Umang
Umang

Reputation: 167

How to transform key to value and value to key in json using jolt spec?

I need to transform (multiple) keys to value and values to keys in JSON using jolt spec. What should be the right spec to do it?

Input :

{
  "k1": "v1",
  "k2": "v2"
}

Required Output :

{
  "v1": "k1",
  "v2": "k2"
}

Upvotes: 1

Views: 1908

Answers (1)

Magda
Magda

Reputation: 482

This should reverse key with value:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "@(0)"
      }
    }
  }
]

Upvotes: 3

Related Questions