Home > Enterprise >  Is their a way to change values in jolt transformation and replace them with custom values
Is their a way to change values in jolt transformation and replace them with custom values

Time:06-17

I have a jolt transformation

{
  "response": [
    {
      "requestDate": 1655285978000,
      "title": "White"
    },
    {
      "requestDate": 1655193656000,
      "title": "White"
    }
  ]
}

In my jolt transformation, I want the value of white to be replaced with black, so that the output should become.

{
  "response": [
    {
      "requestDate": 1655285978000,
      "title": "Black"
    },
    {
      "requestDate": 1655193656000,
      "title": "Black"
    }
  ]
}

Is there a way the content in jolt.

CodePudding user response:

You can use a conditional to separate the cases of the values of title attributes as White and the others within a shift transformation such as

[
  {
    "operation": "shift",
    "spec": {
      "response": {
        "*": {
          "title": {
            "White": {
              "#Black": "&4[&3].&2" // &4 : to substitute "response"(in order to reach four levels up and grab the value), [&3] : to substitute indexes of "response" array, &2 : to get "White" by traversing : and {, eg. two levels up.
            },
            "*": {
              "@1": "&4[&3].&2"
            }
          },
          "*": "&2[&1].&2"
        }
      }
    }
  }
]

the demo on the site enter image description here

  • Related