Forum Discussion

YP's avatar
Occasional Contributor
4 years ago

How to convert JSON to XML using xslt?

Hi All,

How can I convert the below JSON input request to XML format using XSLT I have tried with this XSLT from here but I didn't get desired output and it's throwing an error:"illegal character { at offset 0" in Datapower.

My input request:

    "SMS": [{
            "to": "+966874939494",
            "Message": "<subject+message> "
            "to": "+96687499490",
            "Message": "<subject+message>"

My Expected Output:

<?xml version="1.0" encoding="UTF-8"?>

 Can someone help on this please ? I never even tried Gateway script to give a try.

2 Replies

  • richie's avatar
    Community Hero

    Hi YP 


    do you have to use .xslt or can you use another method?


    Can you just outline the purpose of converting the .json to .xml please?


    Reason I ask is that if you want a response to come back in .xml or .json - you can use an Accept header on the request.


    That is, if you add an 'Accept' header to your request with a value of 'application/xml'- this will force the endpoint to send back the response in .xml rather than .json or vice versa.


    OR - if you just want to convert json to xml - there's an online converter here  and it generated the following:


    <Message><subject+message> </Message>


    It should be remembered that this isn't the only way to represent this in .xml - the 'to' tags could be represented as attributes rather than how they are represented above as elements - so it depends on your requirements.


    I didn't understand why you added in your expected response to your post - was there a reason for that?






    • YP's avatar
      Occasional Contributor

      Hi Richie,


      I have used accept header as well but still it didn't work for me and also not only .xslt need to be used. We have requirement to convert JSON to XML using either XSLT or Gateway script or JQuery.