title: Delicate data manipulation within a javascript object of single-value arrays
body: <p>I have a unique problem that I am trying to solve with some complex javascript code. For your information I am using MongoDB, NodeJS, ExpressJS, and VueJS as my technology stack.</p>
  
  <p>I am writing an application that makes api calls to an outside partner of mine that is returning a huge xml based data file. (Unfortunately they are incapable of sending JSON data). After I receive the data from them, I run it through the parseString command of the xml2js library. But the way that it sends the code back is really really strange. From the outside it looks fine, it's an array of objects: [ {object1},{object2},....{objectN} ]. but when you look at the individual objects, it formats the data strangely:</p>
  
  <hr>
  
  <pre><code>    object1 = {
         key1: [ 'string' ],
         key2: [ '01234657' ],
         key3: [ 'email@email.com' ],
         key4: [{ 
               key5: [ '8372655573' ],
               key6: [ '25.00' ],
               key7: [ 'description of item purchased' ]
               }],
         key8: [ 'otherData' ],
  // .......and so on until
         NthKey: [ 'dataType' ]    
      }
  </code></pre>
  
  <hr>
  
  <p>I anticipated that the majority of the data I was going to receive was going to consist of single key to single data value pairs, with a few exceptions. But for every single key of the returned object from parseString they assign the value to an array as a string, no matter what. And for the times that a key has a bunch of different data types entered into it (such as with key4 in the example above), I have to dig down into not only an array, but also a nested object inside that array, and into the individual keys that are associated with my data.....
  I find that really strange and difficult to work with because now I have to create a bunch of loops that go through and create basically a carbon copy of object 1 except that it looks like this:</p>
  
  <hr>
  
  <pre><code>    object1CarbonCopy = {
          key1: String,
          key2: Number,
          key3: email,
          key4: {
              key5: Number,
              key6: Number,
              key7: String 
          },
          key8: String
  // and so on until........
          NthKey: 'dataType'
      }
  </code></pre>
  
  <hr>
  
  <p>Do any of you have advice on code that could accomplish this? or if there are settings/options that I can pass into xml2js to change how it spits out the data? Any advice at all would be very appreciated.</p>