skip to Main Content

enter image description hereGiven dynamic accountId return the onlineId and signinId for that specific user.

Input JSON:

[
  {
    "request": {
      "body": {
        "inputAccountId": "1234"
      }
    }
  },
  {
    "accountId": "1234",
    "ageGroup": 3,
    "role": 1,
    "gender": "f",
    "signinId": "[email protected]",
    "onlineId": "one"
  },
  {
    "accountId": "1122",
    "ageGroup": 3,
    "role": 2,
    "gender": "f",
    "signinId": "[email protected]",
    "onlineId": "two"
  },
  {
    "accountId": "2211",
    "ageGroup": 1,
    "role": 1,
    "gender": "f",
    "signinId": "[email protected]",
    "onlineId": "three"
  }
]

If accountId = 1234 or accountId could be any account either 1122, or 2211 as well based on use case, then return the output JSON for that accountId.

Jolt:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "request": {
        "inputAccountId": "@(3,request.body.inputAccountId)"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "request": {
        "inputAccountId": "requestedId"
      },
      "1": {
        "*": {
          "accountId": {
            "requestedId": {
              "onlineId": "onlineId",
              "signinId": "signInId"
            }
          }
        }
      }
    }
  }
]

I am not able to get the above code working.. The Java throws error –
java.lang.NullPointerException" when reading the JOLT Spec file.

I also tried ${requestedId} but it goes as numeric, so I added it as requestedId which throws nullPointer exception.

2

Answers


  1. Chosen as BEST ANSWER

    @Barbaros Özhan Do you know how we can get the masked signInID like first characters+@+domainName for the inputId? First character length is based on the nameSize. I have the below logic which works for my other files as per the spec, but in this one I am not able to get to the point -

      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "1": {
            "*": {
              "*": {
                "emailFields": "=split('[@]',@(1,signinId))",
                "nameSize": "=size(@(1,emailFields[0]))",
                "emailName1": "=substring(@(1,emailFields[0]),0,1)",
                "emailName2": "=substring(@(1,emailFields[0]),0,2)",
                "emailName3": "=substring(@(1,emailFields[0]),0,3)",
                "emailName4": "=substring(@(1,emailFields[0]),0,4)",
                "emailName5": "=substring(@(1,emailFields[0]),0,5)",
                "domainSize": "=size(@(1,emailFields[1]))",
                "domainStart": "=intSum(-3, @(1,domainSize))",
                "emailDomain": "=substring(@(1,emailFields[1]), @(1,domainStart), @(1,domainSize))",
                "signinId1": "=join('***@***',@(1,emailName1), @(1,emailDomain))",
                "signinId2": "=join('***@***',@(1,emailName2), @(1,emailDomain))",
                "signinId3": "=join('***@***',@(1,emailName3), @(1,emailDomain))",
                "signinId4": "=join('***@***',@(1,emailName4), @(1,emailDomain))",
                "signinId5": "=join('***@***',@(1,emailName5), @(1,emailDomain))"
              }
            }
          }
        }
      }
    

    How it is accessed in operation -

    "@(2,nameSize)": {
                    "1|2|3|4": {
                      "@(4,signinId1)": "children.@(5,accountId).childSignInId"
                    },
                    "5": {
                      "@(4,signinId2)": "children.@(5,accountId).childSignInId"
                    },
                    "6": {
                      "@(4,signinId3)": "children.@(5,accountId).childSignInId"
                    },
                    "7|8|9": {
                      "@(4,signinId4)": "children.@(5,accountId).childSignInId"
                    },
                    "*": {
                      "@(4,signinId5)": "children.@(5,accountId).childSignInId"
                    }
                  },
    

  2. You can use the following transformation specs :

    [
      { // set values of the object keys to their accountIds
        // while taking out the value of request.body.inputAccountId
        "operation": "shift",
        "spec": {
          "*": {
            "request": {
              "body": {
                "inputAccountId": "inputId"
              }
            },
            "*": {
              "@": "@2,accountId.&"
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "inputId": {
            "*": {
              "@2,&": "[]" // traverse 2 levels to reach 
                             // the value of "inputId" in order
                             // to match with the value of
                             // object keys
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search