I need to perform a Jolt transformation on the below example json:

 "treasure": [
  {
    "name": "FOO",
    "value": 45
  },
  {
    "name": "BAR",
    "value": 20
  },
  {
    "name":"FOOBAR",
    "value":23
]

I need the output to look like:

  {
  "attributes" : {
    "RAB" : 20,
    "OOF" : 45,
    "RABOOF":23
   }

as you can see the BAR is replaced with RAB, FOO with OOF and FOOBAR replaced with RABOOF also used this replacement keys to map with the values in the input. I need to use a IF ELSE to make the replacement of the keys and also after replacing map the values to the keys accordingly What should be the spec here?

This is how far I reached

{
"operation": "shift",
"spec": {
  "*": {
    "treasure": {
      "*": {
        "name":{
          "FOO":{
           "#OOF":"treasure.name"
         },
          "BAR":{
           "#RAB":"treasure.name"
         },
          "FOOBAR":{
           "#RABOOF":"treasure.name"
         }
       }
        
      }
    },
    "@(value)": "[&3].attributes.@(name)"


  
1

There are 1 answers

0
Jagadesh On BEST ANSWER

Check this spec,

[
  {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "name": {
            "FOO": {
              "#OOF": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            },
            "BAR": {
              "#RAB": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            },
            "FOOBAR": {
              "#RABOOF": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            }
          }
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "@(0,value)": "attributes.@(1,name)"
        }
      }
    }
  }
]