Search code examples
jsontransformazure-logic-appsdotliquid

how to use split and replace in same expression in liquid json transformation?


input string -

{"testData":"jack%2C LLC,ville%2C LLC,Nav LLC,50 New Hope%2C LLC,"}

expected output

{"output":"<Value>jack, LLC</Value><Value>ville, LLC</Value><Value>Nav LLC</Value><Value>50 New Hope, LLC</Value>"}

for conversion using this -

%2C is converted to , comma after converting into value tags so that it does not interfare with the delimiter comma.

I tried like below expression

{% 
       "output": "<Value>{{ demo | Split: ',' | Last   }}</Value>",

%}

But need to use replace first to replace %2C to , and then use split string using , and seperate all available values and use <Value> tag.

expected output is -

   {"output":"<Value>jack, LLC</Value><Value>ville, LLC</Value><Value>Nav LLC</Value><Value>50 New Hope, LLC</Value>"}

Solution

  • For this requirement, you can use the liquid template as below:

    {% assign arr = content.testData | Split: "," %}
    {
        "output": "{% for item in arr  %}<value>{{item | Replace: "%2C", ","}}</value>{% endfor %}"
    }
    

    Hope it helps~