Share via


Using Liquid Transform - JSON array to JSON array as simple as possible

Question

Wednesday, September 12, 2018 12:32 PM

In Logic Apps using the Liquid Transform connector I have the followig case.

Input: JSON array, each object having some properties

[
  {
    "Street": "Main Road 13",
    "Zip": "12333",
    "City": "Bigs Ville",
    "Country": "USA"
  },
  {
    "Street": "Main Road 14",
    "Zip": "12444",
    "City": "Small Ville",
    "Country": "Canada"
  }
]

Output: JSON array, each object having slightly different properties

[
  {
    "Address": "Main Road 13, 12333 Bigs Ville",
    "Country": "USA"
  },
  {
    "Address": "Main Road 14, 12444 Small Ville",
    "Country": "Canada"
  }
]

This took me too long to figure out how to do. In the end I am manually rebuilding the JSON array using a for-loop. I even have to manually check whether it is not the last object within the loop, to know if I should output a ',' delimiter between the objects.

[
{%- for item in content -%}
{
"Address":"{{item.Street}}, {{item.Zip}} {{item.City}}",
"Country":"{{item.Country}}"
}{%- if forloop.last == false -%},{%- endif -%}
{%- endfor -%}
]

Are there any better and less chatty ways to transform JSON arrays with liquid transform?

All replies (2)

Thursday, September 13, 2018 11:11 PM âś…Answered | 1 vote

Hey Roitto Gil

Are you looking for an alternative solution within the Liquid Transform functionality or anything alternative? Pretty sure you can achieve the same using Data Operations filters and Control Statements


Friday, September 14, 2018 7:35 AM

Thank you Mike Urnun!

I didn't realize you could do this with Data Oparations Filters, so I am grateful for that tip. I found this article that I think covers my scenario.

However, I can't get it to work. Its no problem to Work with objects using either:

  • for each + Data Operation Compose
  • for each + Data Operation Select

But I cannot find the "Envelope Wrapper" referred in the article, or any other way to get the "merged" resulting array of objects again.