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

本秂侑毒 提交于 2020-04-18 12:33:17

问题


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>"}

回答1:


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~



来源:https://stackoverflow.com/questions/60546659/how-to-use-split-and-replace-in-same-expression-in-liquid-json-transformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!