-1

I am converting a JSON Object as below to XML File for download.

1) JSON:

[
  {
    "entityid": 11,
    "claimid": 221
  },
  {
    "entityid": 11,
    "claimid": 456
  },
  {
    "entityid": 11,
    "claimid": 6478
  },
  {
    "entityid": 11,
    "claimid": 4343
  },
  {
    "entityid": 11,
    "claimid": 444
  },
  {
    "entityid": 11,
    "claimid": 789
  },
  {
    "entityid": 11,
    "claimid": 56
  }
]

2) XML: To start with, I converted the JSON object into XML String but see the numbers displaying for each row... <0>, , <1>, etc...

<0><entityid>11</entityid><claimid>221</claimid></0>
<1><entityid>11</entityid><claimid>456</claimid></1>
<2><entityid>11</entityid><claimid>6478</claimid></2>
<3><entityid>11</entityid><claimid>4343</claimid></3>
<4><entityid>11</entityid><claimid>444</claimid></4>
<5><entityid>11</entityid><claimid>789</claimid></5>
<6><entityid>11</entityid><claimid>56</claimid></6>

3) CODE for conversion of JSON to XML:

var jsonObj = JSON.parse(JSONDownloadString);
console.log(json2xml(jsonObj));

How do I get rid of the numbers at start and end for each record?

Subsequently how do I get this into a file for Download ?

Pls help.

Voila
  • 85
  • 2
  • 15

1 Answers1

0

There is no canonical transformation from JSON to XML. One area where this is particularly obvious is with lists. There is no notion of a list in XML, only a tree of elements. As such you have many options for how you would like to construct lists in XML. The tool you have chosen has made the decision to include the index of the item as an element that wraps the list item. If you don't like that you could find a different tool or manually create the XML yourself.

bhspencer
  • 13,086
  • 5
  • 35
  • 44