LogicApp liquid template json to json transformation

Vijay S 21 Reputation points
2021-01-29T18:00:05.497+00:00

Hi,

i'm tranforming json to json in Logicapps.

  • In my input file Im having 4 elements in array.
    {
    "arrayvalues": [
    {
    "id": 1,
    "tot": 2,
    "vu": "100",
    "props": [
    {
    "find": "ghi",
    "sky": "1000"
    },
    {
    "find": "abc",
    "sky": "500"
    }
    ]
    },
    {
    "id": 2,
    "tot": 1,
    "vu": "500",
    "props": [
    {
    "find": "def",
    "sky": "600"
    }
    ]
    },
    {
    "id": 3,
    "tot": 10,
    "vu": "300",
    "props": [
    {
    "find": "xyz",
    "sky": "700"
    },
    {
    "find": "abc",
    "sky": "2000"
    }
    ]
    },
    {
    "id": 4,
    "tot": 5,
    "vu": "2000",
    "props": [
    {
    "find": "xyz",
    "sky": "900"
    }
    ]
    }
    ]
    }
  • In each element the first 3 values are direct mapping
    Eg:
    id-id, vu-vu, tot-tot (for the mapping of these three values i have done. Please find my attached code here for this). {
    "arrayvalues":[
    {% for i in content.arrayvalues %}
    {
    "id" : "{{i.id}}",
    "vu" : "{{i.vu}}",
    "tot" : "{{i.tot}}",
    }
    {% if forloop.last == false %},{% endif %}
    {% endfor %}
    ]
    }
  • And next i need to verify the key called "find". if this "find" value is "abc".
    Then i need to get that below of the "sky" field value("500").
    (First arrayitem "find" field value is "abc", so i need to take this "sky" field value(500). And also 3rd arrayitem "find" field value is "abc", So from here also i need to take the "sky" field value(2000).
    61939-image.png 61957-image.png
    • And next step is i have to map this "sky" filed values(500 and 2000) with another arrayitems "vu" values.
  • if the "sky" field value is match with one of the "vu" value in that arraitems, then that particular arrayitem output should be like this below.
    {
    "id": "2",
    "tot": "1",
    "vu": "500",
    "Mark": "Yes",
    "Volume": "2"
    },

(Here, The 2nd arrayitem "vu" value is matching with the 1st arrayitem "sky" field value(500). So we need to add "Mark" field and value as "Yes" into it, and "Volume" value we have to take from 1st arrayitem "tot" value, So "Volume" is 2 for this lineitem).

  • if the "vu" field is not match with any of the "sky" value, then that particular arrayitem output should be like this below.
    {
    "id": "3",
    "tot": "10",
    "vu": "300",
    "Mark": "NO",
    "Volume": "0"
    },
    (The 3rd arrayitem "vu" value is not matching with the any "sky" field value, as well as 1st arrayitem "vu" value is also not matching with any "sky" field value).
    (The 2nd arrayitem "vu" value is matching with 1st arrayitem "sky" field value and the 4th arrayitem "vu" value is matching with 3rd arrayitem "sky" field value).

Please find my expected output:
{
"arrayvalues": [
{
"id": "1",
"tot": "2",
"vu": "100",
"Mark": "NO",
"Volume": "0"
},
{
"id": "2",
"tot": "1",
"vu": "500",
"Mark": "Yes",
"Volume": "2"
},
{
"id": "3",
"tot": "10",
"vu": "300",
"Mark": "NO",
"Volume": "0"
},
{
"id": "4",
"tot": "5",
"vu": "2000",
"Mark": "Yes",
"Volume": "10"
}
]
}

Please help me in this to solve this....

Regards,
Vijay

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

Accepted answer
  1. MayankBargali-MSFT 70,731 Reputation points
    2021-02-01T09:08:49.043+00:00

    Hi @Vijay S

    Welcome to Microsoft Q&A! Thanks for posting the question.
    The query is more towards the open source liquid template implementation rather than integrating the liquid template with logic app.
    I will suggest you to post your query here with liquid tagged so your query is available to the larger audience having liquid template creation experts.

    If you are already familiar with the liquid then I will suggest you to leverage this to play around with the input JSON, template, and the expected output that you need. Once you have tested your liquid template you can leverage this document to integrate liquid template with logic app.

    Feel free to get back to me if you need any assistance in the integration of your liquid template in the logic app.


0 additional answers

Sort by: Most helpful

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.