Split string based on string length in dotliquid

275 Views Asked by At

I have a scenario where I need to split a string say "VIP tickets John Smith concert today at 4pm and later dinner" into parts where each part is upto 35 chars long. I can see for and slice but this has to be done in a loop to create following json

{
   "Informations": [
      {
         "Information": "VIP tickets John Smith concert toda"
      },
      {
         "Information": "y at 4pm and later dinner"
      }
   ]
}

how should I slice it? I am trying to write liquid transformation for logic app

{
   "Informations": [
      {
         "Information": "VIP tickets John Smith concert toda"
      },
      {
         "Information": "y at 4pm and later dinner"
      }
   ]
}
1

There are 1 best solutions below

2
vijaya On

Using Slice expression and compose action, you can split string into multiple words and form the Json. Below are steps I followed,

  • Designer of logic app can be shown below, enter image description here
  • In Initialize variable action, Initialized string variable with value "VIP tickets John Smith concert today at 4pm and later dinner" enter image description here
  • In second Initialize variable action, splitting string variable with expression slice(variables('string var'),0,35). This will split string into another string with length of 35. enter image description here
  • In third Initialize variable action, splitting string variable with expression

slice(variables('string var'),35,70).This will split string into another string with length of 35. enter image description here

  • In compose action forming array with above two sliced strings, enter image description here
  • Next taken loop and passing input from compose output. Using another compose action in loop as shown below, enter image description here
  • At last using another compose action to form required json as show below, enter image description here
  • Below is output of logic app, enter image description here

Output of Initialize variable 2&3

enter image description here

Output of last compose action,

enter image description here