Input json :
{
"userid" : "31b25f023c58c969388991a6b9b4030000000000",
"username_id": "54fca0dd914ae593ef65988b4a3e93cccc590000000000"
}
There is 10 0's ahead of each value. The overall length of string can vary, but it will be appended by 10 0's always. I would like to remove it.
Thus expected output:
{
"userid" : "31b25f023c58c969388991a6b9b403",
"username_id": "54fca0dd914ae593ef65988b4a3e93cccc59"
}
Hence i am looking for the right way using jolt transform to perform this truncation.
CodePudding user response:
You can start with a modify transformation in which the substring function is applied for each value of the attributes after determining their ten reduced length in order to extract the value except for the last ten characters, as it's mentioned ten zeroes are always right-padded, such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"userid_len": "=size(@(1,userid))",
"userid_len_dif": "=intSum(-10,@(1,userid_len))",
"userid": "=substring(@(1,&),0,@(1,userid_len_dif))",
"username_id_len": "=size(@(1,username_id))",
"username_id_len_dif": "=intSum(-10,@(1,username_id_len))",
"username_id": "=substring(@(1,&),0,@(1,username_id_len_dif))"
}
},
{
"operation": "shift",
"spec": {
"use*id": "&"
}
}
]