user11170425
user11170425

Reputation: 31

How to compare filed values in JOLT transformation?

I have the input like below,

Input:

{
  "a": 1,
  "b": 2
}

Spec:

[
 {
  "operation": "shift",
  "spec": {
    "a": {
      "@(2,b)": {
        "#Matched": "result"
      },
      "*": {
        "#Not Matched": "result"
      }
    }
  }
}]

Output:

{
 "result" : [ "Matched", "Not Matched" ]
}

Expected:

{
 "result" : "Not Matched" 
}

Can anyone please suggest me help to work it as usual.

Upvotes: 1

Views: 1524

Answers (1)

regular
regular

Reputation: 31

You can transform it in three steps:

  1. move values to keys
  2. find matched key
  3. add "Not match" result if matched key was not found

(can't imagine why it doesn't work with values)

Smth like:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&.@0"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "a": {
        "*": {
          "@(2,b.&)": {
            "#Matched": "result"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "result": "Not Matched"
    }
  }
]

Upvotes: 1

Related Questions