Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Compare XML and Json Response

Kishore
Kishore Posts: 2

Planning to move a service from Soap to Rest Json. I would like to prepare a test suite that help me compare the old Soap XML response with the JSON response.

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    You could write a script to covert the XML to JSON or the JSON to XML and then compare the documents after conversion. However, there is no universal way to map XML elements to JSON objects/arrays (or vice versa). This is especially true with respect to XML namespaces, XML attributes, and repeating XML elements. There are similarly different ways to map JSON arrays (single and multi-dimensional) to XML elements. There are different libraries for doing conversions but they all behave differently. Some are good about converting for JSON to XML and back but not the other way around. Similarly, others are good at converting XML to JSON and back but not the other way around. Basically, you end up with JSON-looking XML or XML-looking JSON. There's a good document from W3C I like to refer back to that describes the trouble and complications mapping between the two message formats. There is no good 1-to-1 mapping between JSON and XML. So, how things from your XML messages map to your new JSON messages would be somewhat specific to your service implementation.

    You might also consider simply updating your tests to assert on the new JSON messages directly instead of trying to convert and compare the old XML messages against the new JSON messages.

  • Kishore
    Kishore Posts: 2

    I am more inclined to use the asserting the json response fields to corresponding xml values. I have multiple lines of values which i need to implement. Let me try that method.
    thanks.