Home > front end >  Jolt Transform If Else Condition on keys?
Jolt Transform If Else Condition on keys?

Time:06-22

Any way we can use if else conditions in Jolt Transform :

Input :

{
  "treasure": [
    {
      "aname": "FOO",
      "bname": "BAR"
    }
  ]
}

Output :

If aname is "FOO" then change to fname else let it be to aname.

{
  "fname" : "FOO",
  "sname" : "BAR"
}

CodePudding user response:

Yep, I can confirm that that answer gives the correct output but so does:

[
  {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "aname": "fname",
          "bname": "sname"
        }
      }
    }
  }
]

When you say you're after if/else, do you mean that you want either "aname" or "bname" to feed into "fname"?

Currently, your solution is just a direct mapping of "aname" > "fname" and "bname" > "sname".

CodePudding user response:

Jolt Spec for If - Else:

[
  {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "aname": {
            "FOO": {
              "@(2,aname)": "aname"
            },
            "*": {
              "@(2,aname)": "gname"
            }
          },
          "bname": {
            "BAR": {
              "@(2,bname)": "bname"
            },
            "*": {
              "@(2,bname)": "gname"
            }
          }
        }
      }
    }
  }
]
  • Related