Home > Enterprise >  Jolt - How to Update Key with value given with that key
Jolt - How to Update Key with value given with that key

Time:10-14

How we can make a dynamic key based on value in Jolt?

JSON input is like

{
  "Rating": 1,
  "SecondaryRatings": {
    "Design": 4,
    "Price": 2,
    "RatingDimension3": 1
  }
}

And expected output should be like

{
  "rating-primary-1" : 1,
  "rating-Design-4" : 4,
  "rating-Price-2" : 2,
  "rating-RatingDimension3-1" : 1
}

Current Spec is

[
  {
    "operation": "shift",
    "spec": {
      "Rating": "rating-primary",
      "SecondaryRatings": {
       "*": "rating-&"
      }
    }
  }
]

CodePudding user response:

You can use two consecutive shift transformation specs such as

[
  {
   // determine object tags with desired prefixes
    "operation": "shift",
    "spec": {
      "Rating": "rating-primary-.@(1,&)",
      "SecondaryRatings": {
        "*": "rating-&-.@(1,&)"
      }
    }
  },
  {
   // then combine those keys with attribute keys inside each object 
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1&"
      }
    }
  }
]

the demo on the site enter image description here

  • Related