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).
- 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