Forum Discussion

itaykaldi's avatar
itaykaldi
Contributor
12 years ago

Cannot convert JSON to XML

Hey,
I got the following JSON response

"{\u000d\u000a \"$type\": \"Cloud.Messages.DeviceMessages.GetCCResponseDeviceMessage, DeviceMessages\",\u000d\u000a \"Cards\": {\u000d\u000a \"$type\": \"System.Collections.Generic.List`1[[Cloud.Messages.DeviceMessages.Card, DeviceMessages]], mscorlib\",\u000d\u000a \"$values\": []\u000d\u000a },\u000d\u000a \"Status\": 0\u000d\u000a}"

How can i convert this response to to XML?
  • Hi,
    The response looks bit strange.
    In SoaupUI response editor- there is an XML view which automatically converts the JSON response to XML when you click on XML tab.
    Is that what you are looking for?

    Best Regards,
    Prakash
    SmartBear Sweden
  • As I mentioned earlier, the response doesn't look correct JSON.
    I tried to convert it to XML using: http://www.utilities-online.info/xmltojson/ but it failed.
    It converts to XML correctly if I change the response text to:
    { "$type": "Cloud.Messages.DeviceMessages.GetCCResponseDeviceMessage, DeviceMessages","Cards": {"$type": "System.Collections.Generic.List`1[[Cloud.Messages.DeviceMessages.Card, DeviceMessages]], mscorlib","$values": [] },"Status": 0}

    So, I think the service should be fixed to return the correct JSON (if possible), otherwise you can write a Groovy script to parse the response into valid JSON or XML.

    Best Regards,
    Prakash
    SmartBear Sweden