Showing results for 
Search instead for 
Did you mean: 

How to convert JSON to XML using xslt?

Occasional Contributor

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.

Tags (3)
Community Hero

Re: How to convert JSON to XML using xslt?

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?






if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Occasional Contributor

Re: How to convert JSON to XML using xslt?

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.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors