title: Removing extra brackets and data from JSON object - Javascript
body: <p>I'm parsing an XML file with this function:</p>
  
  <pre><code>function xmlToJson(xml) {
      var attr, child, attrs = xml.attributes,
          children = xml.childNodes,
          key = xml.nodeType,
          obj = {},
          i = -1,
          o = 0;
      if (key == 1 &amp;&amp; attrs.length) {
          obj[key = o] = {};
          while (attr = attrs.item(++i)) {
              obj[key][attr.nodeName] = attr.nodeValue;
          }
          i = -1;
      } else if (key == 3) {
          obj = xml.nodeValue;
      }
      while (child = children.item(++i)) {
          key = child.nodeName;
          if (obj.hasOwnProperty(key)) {
              if (obj.toString.call(obj[key]) != '[object Array]') {
                  obj[key] = [obj[key]];
              }
              obj[key].push(xmlToJson(child));
          } else {
              obj[key] = xmlToJson(child);
          }
      }
      return obj;
  }
  </code></pre>
  
  <p>Parsing the next file results in the below string (seen using JSON.stringify):</p>
  
  <p>File (not including the '&lt;' chars because the content is not visible then, but in my file obviously I've got them):</p>
  
  <pre><code>?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  playlist&gt;
  vid src="video/intro.mp4" type="video/mp4"/&gt;
  vid src="video/intro.mp4" type="video/mp4"/&gt;
  /playlist&gt;
  </code></pre>
  
  <p>JSON:</p>
  
  <pre><code>{"playlist":{"#text":["\n","\n","\n"],"vid":[{"0":{"src":"video/intro.mp4","type":"video/mp4"}},{"0":{"src":"video/intro.mp4","type":"video/mp4"}}]}}
  </code></pre>
  
  <p>but I need the output to be just:</p>
  
  <pre><code>[{"0":{"src":"video/intro.mp4","type":"video/mp4"}},{"0":{"src":"video/intro.mp4","type":"video/mp4"}}]
  </code></pre>
  
  <p>Sorry if noob question, but I'm as new to JS as to JSON, and the days I'm with them can be counted with the fingers of one of my hands.</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: SOLVED - Solved by myself: Instead of being rude not allowing the object to be converted into a string, I've decided to convert it, 'substring' it and then reconvert the remaining string back. This is the result:</p>
  
  <pre><code>JSON.parse(JSON.stringify(jsonPlaylist).substring(44,JSON.stringify(jsonPlaylist).length-2));
  </code></pre>
  
  <p>Supposing that <code>jsonPlaylist</code> is the string var containing the whole parsed XML file.</p>