skip to Main Content

I’m new to Jolt transformations. I will try to describe my case in detail.
I suspect that you will need to combine shift and modify-default operations

HERE: TRANSFORMATION RULE:
if field detail have value (exist and is not"" or null)
then map detail => updating_field
else:
map updating_field => updating_field

INPUT

{
  "updating_field": "ACCEPT",
  "channel": {
    "detail": null
  }
}

EXPECTED OUTPUT for e.g. detail = null value inside JOLT

{
  "channel": {
    "updating_field": "ACCEPT"
  }
}

OTHER INPUT

{
  "updating_field": "ACCEPT",
  "channel": {
    "detail": "normal_value"
  }
}

OTHER EXPECTED OUTPUT for e.g. **detail = "normal_value" value inside JOLT

{
  "channel": {
    "updating_field": "normal_value"
  }
}

Thanks in advance for any help.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks a lot. Can you give me advice how to keep above logic and add another one where we get more field inside channel block and how handle value with empty string "".

    I mean INPUT like

    {
      "updating_field": "ACCEPT",
      "channel": {
        "detail": "",
        "next_field": "new_value_need_shift"
      }
    }
    

    OUTPUT

    {
      "channel": {
        "detail": "ACCEPT",
        "next_field": "new_value_need_shift"
      }
    }
    

  2. You can use the ~ operator within a modify-overwrite-beta transformation such as

    "~detail" : "@(2,updating_field)" meaning if "detail" does not exist or is null,

    then make it be the value of "updating_field" after traversing 2 levels (: and {) up the tree such as

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "c*": {
            "~detail": "@(2,updating_field)"
          }
        }
      },
      { // rename the key from "detail" to "updating_field"
        "operation": "shift",
        "spec": {
          "c*": { // the level of "channel" where * stand for abbreviation
            "*": "&1.updating_field"
          }
        }
      }
    ]
    

    the first demo on the http://jolt-demo.appspot.com/ site is :

    enter image description here

    the second demo on the http://jolt-demo.appspot.com/ site is :

    enter image description here

    Edit : If the null and empty string ("") values should be classifed as in the same category, then use ths size function as follows :

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "c*": {
            "sz": ["=size(@(1,detail))", 0]
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "c*": {
            "sz": {
              "0": { "@3,updating_field": "&3.updating_field" },
              "*": { "@2,detail": "&3.updating_field" } // else case
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search