Sunnydays
Sunnydays

Reputation: 45

Using Jolt transform to use value of a key to locate another value in map

I need to use value of a field to lookup another value in map.

{
  "name": "Smith",
  "Occupation": {
    "Smith": "Engineer",
    "John": "Plumber",
    "Mary": "Doctor"
  }
}

output:

{
  "Name": "Smith",
  "Job": "Engineer"
}

how to do this using jolt?

Upvotes: 1

Views: 42

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65383

You can use such a single shift transformation :

[
  {
    "operation": "shift",
    "spec": {
      "name": {
        "*": {
          "@(2,Occupation.&)": "Job"
        },
        "@": "&"//replicates "name" itself
      }
    }
  }
]

the demo on the site Jolt Transform Demo Using v0.1.1 is :

enter image description here

Upvotes: 2

Related Questions