title: JSON to XML Using Javascript
body: <p>I am trying to convert the JSON to XML  but not getting exact output.In My JSON having array object it not converting that to XML array.Mainly   array object is not converting into XML as expected</p>
  
  <pre class="lang-js prettyprint-override"><code>var InputJSON = "{"body":{"entry": [{ "fullURL" : "abcd","Resource": "1234"},{ "fullURL" : "efgh","Resource": "5678"}]}}";
  var output = eval("OBJtoXML("+InputJSON+");")
  
  function OBJtoXML(obj) {
      var xml = '';
      for (var prop in obj) {
          xml += "&lt;" + prop + "&gt;";
          if(obj[prop] instanceof Array) {
              for (var array in obj[prop]) {
                  xml += OBJtoXML(new Object(obj[prop][array]));
              }
          } else if (typeof obj[prop] == "object") {
              xml += OBJtoXML(new Object(obj[prop]));
          } else {
              xml += obj[prop];
          }
          xml += "&lt;/" + prop + "&gt;";
      }
      var xml = xml.replace(/&lt;\/?[0-9]{1,}&gt;/g,'');
      return xml
  }
  </code></pre>
  
  <p>Actual Output:
  </p>
  
  <pre><code>&lt;body&gt;
    &lt;entry&gt;
      &lt;fullURL&gt;abcd&lt;/fullURL&gt;
      &lt;Resource&gt;1234&lt;/Resource&gt;
      &lt;fullURL&gt;efgh&lt;/fullURL&gt;
      &lt;Resource&gt;5678&lt;/Resource&gt;
    &lt;/entry&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Expected Output:
  </p>
  
  <pre><code>&lt;body&gt;
    &lt;entry&gt;
      &lt;fullURL&gt;abcd&lt;/fullURL&gt;
      &lt;Resource&gt;1234&lt;/Resource&gt;
    &lt;/entry&gt;
   &lt;entry&gt;
      &lt;fullURL&gt;efgh&lt;/fullURL&gt;
      &lt;Resource&gt;5678&lt;/Resource&gt;
    &lt;/entry&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Please guide me if i am missing anything from the code to get my expected result</p>