Liquid Filter "Where:" not working in Consumption Logic App JSON to JSON transformation

Simon Björkén 0 Reputation points
2023-10-09T17:35:03.0333333+00:00

I'm building a liquid map file to pull together data from two arrays in the same JSON file, and would like to use the "Where:" filter to select the correct object in the array, respective to the first array I am looping over.

My file looks something like this below:

{
    "content": {
        "product": [
            {
                "title": "Spoon",
                "type": "Kitchen"
            },
            {
                "title": "Table",
                "type": "Living"
            },
            {
                "title": "Kettle",
                "type": "Kitchen"
            },
            {
                "title": "TV",
                "type": "Living"
            }
        ],
		"product_metadata": [
			{
				"article": "Spoon",
				"description": "10"
			},
			{	
				"article": "Table",
				"description": "20"
			}
		]
    }

I then try to create a new product object using Liquid code similar to below. This is using the logic app implementation of liquid so using capitalized filter operators. I've also tried with hardcoded values to match the article property with (i.e "Spoon" or "Table") but to no success. I end up with nothing in the metadata variable and adding " | First " to the end of the assign metadata line just gives me the first object in the product_metadata-array.

{% for entry in content.product %}
{% assign metadata = content.product_metadata | Where: "article", entry.title %}
{
	"article": "{{ entry.title }}",
	"type": "{{ entry.type }}",
	"description": "{{ metadata.description }}"
} {%- unless forloop.last -%},{%- end unless -%}
{% endfor %}

Am I missing something or is this a bug or still a method/filter not supported in the dotliquid implementation? Checking the source code on Github, the Where filter seems to be supported, though I did see a ticket/forum post about this issue in 2019: https://social.msdn.microsoft.com/Forums/en-US/c536ec41-2f60-4211-87ea-a0b5f56402e1/liquid-map-where-filter?forum=azurelogicapps

All and any help very appreciated!

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,553 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2023-10-10T05:46:33.2533333+00:00

    @Simon Björkén Thanks for reaching out and apology for the inconvenience due to this issue.

    As per the document I can see that currently logic app uses the DotLiquid 2.0.361 which was released on 6/24/2020 by Dotliquid as mentioned here. The where was implemented post 7th June 2021 as per this pull request at Dotliquid end so DotLiquid 2.0.361 doesn't support it. I will reconfirm with my team if the DotLiquid has been updated to any other version which supports where liquid filter.

    I will keep you posted once I hear back from my team.

    Update:

    Logic app is still using the DotLiquid 2.0.361 and we will update our document once it is updated to the new versions.

    The workaround would be leveraging the inline JavaScript function or offload this function to azure function and call azure function from logic app which will have your custom code for the transformation.

    Please "Accept Answer" if the answer is helpful so that it can help others in the community.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.