We have been using xml2Json for a while. As of this week, we are getting ‘occasional’ console errors stating it has been deprecated and to use ‘require(‘xml2js’)’ instead.
On doing this, the format that is created is not as we had before - I am sure there is something really simple we are missing
This is from xml2Json
This is from xml2js
We obviously would like it to have remained the same so our tests do not need rework.
I had essentially the same issue and was able to fix it by setting the explicitArray flag to false, similar to what the previous comment mentioned. It should remove the array structures and 0’s from the json object. There may be other differences but I haven’t came across any in the XML responses I’ve worked with recently.
Hi,
Thank you for this snipplet, it allows me to display the response in the console in json format (removing the last line with the deprecated xml2Json).
I am struggling to understand how I can access a particular element of the json object, e.g. the “CoverType” from the above example. I just can’t make it work. Would you be able to provide a line that displays the CoverType in the console? Thank you!
Hi. Thanks for trying to help. I finally made it work, just after I posted the message… typical. I had a typo in my code (mixup between capital i and small L…), my bad! Additional debugging helped. Sorry for the unnecessary question after all :-/