Azure Logic App Liquid Template Transformation from XML with namespace to JSON

Dino Filipovic 21 Reputation points
2021-05-12T13:14:27.05+00:00

Hello,

I have a question about Liquid template where I need to transform XML to JSON for purpose of integration with API.

XML looks like this and I can transform it when I don't have namespace in XML but I have a problem with namespace here.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Document xmlns:dyn="http://www.w3.org/2000/dyn/;">
  <dyn:LedgerJournalEntity>
    <dyn:AccountDisplayValue></dyn:AccountDisplayValue>
    <dyn:AccountType>Cust</dyn:AccountType>
    <dyn:CreditAmount>100.00</dyn:CreditAmount>
    <dyn:CurrencyCode>EUR</dyn:CurrencyCode>
    <dyn:DebitAmount>0.00</dyn:DebitAmount>
    <dyn:DefaultDimensionDisplayValue>1-1410-45-</dyn:DefaultDimensionDisplayValue>
    <dyn:Description>TEST_GL_EXPORT</dyn:Description>
    <dyn:InvoiceDueDate_BeELES>2021-04-08T00:00:00</dyn:InvoiceDueDate_BeELES>
    <dyn:InvoiceId_BeELES>RIR-000252</dyn:InvoiceId_BeELES>
    <dyn:JournalBatchNumber>TEST</dyn:JournalBatchNumber>
    <dyn:JournalName>TEST</dyn:JournalName>
    <dyn:LineNumber>10000</dyn:LineNumber>
    <dyn:OffsetAccountDisplayValue></dyn:OffsetAccountDisplayValue>
    <dyn:OffsetAccountType>Ledger</dyn:OffsetAccountType>
    <dyn:OffsetDefaultDimensionDisplayValue></dyn:OffsetDefaultDimensionDisplayValue>
    <dyn:PostingProfile>PLK</dyn:PostingProfile>
    <dyn:Text>TEST TEXT</dyn:Text>
    <dyn:TransDate>2021-05-12T00:00:00</dyn:TransDate>
  </dyn:LedgerJournalEntity>
    <dyn:LedgerJournalEntity>
    <dyn:AccountDisplayValue></dyn:AccountDisplayValue>
    <dyn:AccountType>Cust</dyn:AccountType>
    <dyn:CreditAmount>100.00</dyn:CreditAmount>
    <dyn:CurrencyCode>EUR</dyn:CurrencyCode>
    <dyn:DebitAmount>0.00</dyn:DebitAmount>
    <dyn:DefaultDimensionDisplayValue>1-1410-45-</dyn:DefaultDimensionDisplayValue>
    <dyn:Description>TEST_GL_EXPORT</dyn:Description>
    <dyn:InvoiceDueDate_BeELES>2021-04-08T00:00:00</dyn:InvoiceDueDate_BeELES>
    <dyn:InvoiceId_BeELES>RIR-000252</dyn:InvoiceId_BeELES>
    <dyn:JournalBatchNumber>TEST</dyn:JournalBatchNumber>
    <dyn:JournalName>bcpay</dyn:JournalName>
    <dyn:LineNumber>10000</dyn:LineNumber>
    <dyn:OffsetAccountDisplayValue></dyn:OffsetAccountDisplayValue>
    <dyn:OffsetAccountType>Ledger</dyn:OffsetAccountType>
    <dyn:OffsetDefaultDimensionDisplayValue></dyn:OffsetDefaultDimensionDisplayValue>
    <dyn:PostingProfile>PLK</dyn:PostingProfile>
    <dyn:Text>TEST TEXT</dyn:Text>
    <dyn:TransDate>2021-05-12T00:00:00</dyn:TransDate>
  </dyn:LedgerJournalEntity>
</Document>

This is my Liquid template which I have built for this purpose.

{
"LEDGERJOURNALENTITY": [
{% JSONArrayFor data in content.Document.LEDGERJOURNALENTITY %}
{
"AccountDisplayValue": "{<!-- -->{data.ACCOUNTDISPLAYVALUE}}",
"AccountType": "{<!-- -->{data.ACCOUNTTYPE}}",
"CreditAmount": "{<!-- -->{data.CREDITAMOUNT}}",
"CurrencyCode": "{<!-- -->{data.CURRENCYCODE}}",
"DebitAmount": "{<!-- -->{data.DEBITAMOUNT}}",
"DefaultDimensionDisplayValue":"{<!-- -->{data.DEFAULTDIMENSIONDISPLAYVALUE}}",
"Description": "{<!-- -->{data.DESCRIPTION}}",
"InvoiceId_BeELES": "{<!-- -->{data.INVOICEID_BeELES}}",
"InvoiceDueDate_BeELES": "{<!-- -->{data.INVOICEDUEDATE_BeELES}}",
"dataSalesTaxGroup": "{<!-- -->{data.dataSALESTAXGROUP}}",
"JournalBatchNumber": "{<!-- -->{data.JOURNALBATCHNUMBER}}",
"JournalName": "{<!-- -->{data.JOURNALNAME}}",
"LineNumber": "{<!-- -->{data.LINENUMBER}}",
"OffsetAccountDisplayValue":"{<!-- -->{data.OFFSETACCOUNTDISPLAYVALUE}}",
"OffsetAccountType":"{<!-- -->{data.OFFSETACCOUNTTYPE}}",
"OffestDefaultDimensionDisplayValue":"{<!-- -->{data.OFFSETDEFAULTDIMENSIONDISPLAYVALUE}}",
"PostingProfile":"{<!-- -->{data.POSTINGPROFILE}}",
"SalesTaxCode":"{<!-- -->{data.SALESTAXCODE}}",
"SalesTaxGroup":"{<!-- -->{data.SALESTAXGROUP}}",
"Text":"{<!-- -->{data.TEXT}}",
"TransDate":"{<!-- -->{data.TRANSDATE}}"
}
{% endJSONArrayFor %}
]
}

Can someone help me with this so I can solve this problem?

Best regards,
Dino

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

Accepted answer
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2021-05-13T08:24:30.177+00:00

    Hi @Dino Filipovic

    Welcome to Microsoft Q&A! Thanks for posting the question.

    I have tested the XML file at my end with the below liquid template and was able to convert the XML to a JSON object. For testing, I have converted only a few fields. You can update the .liquid file according to your requirement. You can also refer to this document.

    96312-image.png

    .liquid template:

    {  
        "LedgerJournalEntity": [  
            {% for data in content.Document %}  
            {  
    		    "AccountDisplayValue": "{{data.AccountDisplayValue}}",  
                "AccountType": "{{data.AccountType}}",  
                "CreditAmount": {{data.CreditAmount}},  
    			"CurrencyCode": "{{data.CurrencyCode}}"  
      
            },  
            {% endfor %}  
        ]  
    }  
    

    Output:

    {  
      "LedgerJournalEntity": [  
        {  
          "AccountDisplayValue": "",  
          "AccountType": "Cust",  
          "CreditAmount": 100,  
          "CurrencyCode": "EUR"  
        },  
        {  
          "AccountDisplayValue": "",  
          "AccountType": "Cust",  
          "CreditAmount": 100,  
          "CurrencyCode": "EUR"  
        }  
      ]  
    }  
    

    Hope the above helps you to resolve the issue. Feel free to get back to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

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.