Search code examples
jsontransformjolt

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?


Solution

  • 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