I want to transform a complex json to a expected json structure in Azure Logic App. I have converted the input json to xml and created XSLT file to apply the transformation. Using XML Transform action from Logic App, I tried converting it to expected xml format and convert back the same to json. I encountered issue with nested arrays which are not picking up correct child value and I can see it has picked up random child of the parent array. I really need to fix this.
I’m exploring doing it with xsl:apply-templates meanwhile looking for error resolution in this.
what I tried:
Input xml:
{
"?xml": {
"@version": "1.0",
"@encoding": "utf-8"
},
"Model": {
"EmpDetails": {
"Emp": [
{
"EmpId": "32370",
"Job": {
"EmpJob": {
"JobId": "2121470-2"
}
}
},
{
"EmpId": "30413",
"Job": {
"EmpJob": {
"JobId": "2121470"
}
}
},
{
"EmpId": "32372",
"Job": {
"EmpJob": {
"JobId": "2121470-4"
}
}
},
{
"EmpId": "32371",
"Job": {
"EmpJob": {
"JobId": "2121470-3"
}
}
}
]
}
}
}
XSL File:
<employmentDetails>
<xsl:for-each select="/Model/EmpDetails">
<employments>
<employmentId>
<xsl:value-of select="EmpId"/>
</employmentId>
<xsl:for-each select="Job">
<jobs>
<jobUserId>
<xsl:value-of select="EmpJob/JobId"/>
</jobUserId>
</jobs>
</xsl:for-each>
</employments>
</xsl:for-each>
</empDetails>
Output Result I’m Getting: jobUserId is mostly populated random and changes everytime.
{
"employmentDetails": {
"employments": [
{
"EmpId": "32370",
"jobs": {
"jobUserId": "2121470-2"
}
},
{
"EmpId": "30413",
"jobs": {
"jobUserId": "2121470-2"
}
},
{
"EmpId": "32372",
"jobs": {
"jobUserId": "2121470-4"
}
},
{
"EmpId": "32371",
"jobs": {
"jobUserId": "2121470-4"
}
}
]
}
}
Output Result expected:
{
"employmentDetails": {
"employments": [
{
"EmpId": "32370",
"jobs": {
"jobUserId": "2121470-2"
}
},
{
"EmpId": "30413",
"jobs": {
"jobUserId": "2121470"
}
},
{
"EmpId": "32372",
"jobs": {
"jobUserId": "2121470-4"
}
},
{
"EmpId": "32371",
"jobs": {
"jobUserId": "2121470-3"
}
}
]
}
}
Sneha Guled is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.