working on a DataWeave transformation and need some help converting a string to a compressed format. Here’s the requirement:
{ "string":"AAAAAABBBBCCCDD" }
{ "string":A6B4C3D2 }
In the output, I want to count consecutive characters and represent them in a compressed format.
You can get the desired output by grouping the continuous same characters and then concatenate each character with its counting. check below DataWeave Script
here input is
{
"inputString": "AAAAAABBBBCCCDD"
}
solution to get desired output is:
%dw 2.0
output application/json
var test = payload.inputString groupBy ($)
---
{
"String": (keysOf(test) map($ ++ sizeOf(test[$]))) joinBy ""
}