skip to Main Content

Trying to find the middle initial Jolt configuration. Ask is, i need to consider only first character in Middle name return from Json. Also first character should be Alphabet (either caps or small case), else i need to return null.

M. -> M.  
M$ -> M  
$M -> null  
.M -> null  
Mary -> M  
1Mary --> null

Input 1:

{
  "applicant": {
    "firstName": "Mary",
    "middleName": "M.",
    "lastName": "Coker"
  }
}

Input 2:

{
  "applicant": {
    "firstName": "Mary",
    "middleName": "$M",
    "lastName": "Coker"
  }
}

Desired Output for 1:

{
  "applicant": {
    "firstName": "Mary",
    "middleName": "M",
    "lastName": "Coker"
  }
}

Desired Output for 2:

{
  "applicant": {
    "firstName": "Mary",
    "middleName": null,
    "lastName": "Coker"
  }
}

2

Answers


  1. Enjoy 🙂

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "applicant": {
            "x_middleNameFirstChar": "=substring(@(1,middleName), 0, 1)",
            "x_aphabetStr": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
            "x_alphabetSplit": "=split(@(1,x_middleNameFirstChar),@(1,x_aphabetStr))",
            "x_splitSize": "=size(@(1,x_alphabetSplit))",
            "middleName": null
          }
        }
        }
      ,
      {
        "operation": "shift",
        "spec": {
          "applicant": {
            "x_*": null,
            "*": "applicant.&",
            "x_splitSize": {
              "2": {
                "@(2,x_middleNameFirstChar)": "applicant.middleName"
              }
            }
          }
        }
       }
    ]
    
    Login or Signup to reply.
  2. You can use toLower and toUpper functions those have respectively different impacts for letters which are the first characters of middleName s while have no impact on non-alphabetic chars such as

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "middleName": "=substring(@(1,&),0,1)",
            "up": "=toUpper(@(1,middleName))",
            "lw": "=toLower(@(1,middleName))"
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1.&",
            "up|lw": { "$": "&2.extra.@0" }
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "extra": "=size"
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1.&",
            "middleName": { //get rid of the previosly derived "middleName" value
              "": ""
            },
            "extra": {
              "1": { // match middleName with a null 
                //if both of the derived "middleName" values are equal
                "@": "&3.middleName"
              },
              "2": { //keep the derived "middleName" value if the first character is a letter
                //eg.there are two different letters : upper one vs. lower one
                "@2,middleName": "&3.middleName"
              }
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search