I am trying to get the number of entries in an XML response by converting it to Json.
The response has this content type:
Content-Type: application/xml; charset=utf-8
But running this in Test does not give the expected output:
var jsonObject = xml2Json(responseBody);
console.log(typeof jsonObject); – object. How do I get a Json object?
console.log(jsonObject.length); – undefined
Output:
“object”
undefined
How can I fix this so I can count entries in the response?
Response example:
<?xml version="1.0" encoding="utf-16"?> <CIM xmlns:DT="CIM_DataTypes"> <party> <rank>D</rank> <partyId>2348703043</partyId> </party> <party> <rank>E</rank> <partyId>2334403020</partyId> </party> </CIM>
console.log(jsonObject);
outputs something like this:
{CIM: {…}}
CIM: {…}
$: {…}
xmlns:DT: "CIM_DataTypes"
Party: [399]
0: {…}
rank: "D"
partyId: "2348703043"
1: {…}
2: {…}
.
.
.