Search code examples
jsonazureazure-logic-appsdotliquid

How to use substring operation in liquid json to json transformation?


I'm using Json to Json transformation using Integration Account in Logic app.

my input is -

{"MyText" : "S-12-678"}

expected output -

{
"First-Data":"678",
"Second-Data":"S-12"
}

For above expected output I have created mydemo.liquid file like below working good for First-Data field but unable to get "Second-Data":"S-12" How to achieve it?

{
   "First-Data": "{{content.MyText | Split: '-' | Last }}",
   "Second-Data": "{{content.MyText | Split: '-' | First}}"
}

Solution

  • You can use the liquid template below:

    {% assign arr = content.MyText | Split: "-" %}
    {
        "First-Data": "{{arr[2]}}",
        "Second-Data": "{{arr[0]}}-{{arr[1]}}"
    }
    

    Then the result is what you expected: enter image description here