title: Generating JSON from a xml document / Powershell / controlling the array format
body: <p>I need to read some data from an XML document and then format it as JSON to submit as a POST to a new webservice we're deploying.</p>
  
  <p>While I got <em>most</em> of it to work, I'm not really happy with how the JSON is coming out (I can modify the webservice if needed, so the data format issue I have now is mostly cosmetic).</p>
  
  <p>So... Data source (the xml file):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ConfigRepository ServiceUri="http://somemachine"
                    ConnectionTimeout="10000"
                    CacheEnabled="true"
                    CacheExpirationDuration="600"
                    ServiceMonitorPollDuration="10" /&gt;
  </code></pre>
  
  <p>Powershell code reading this/generating the JSON:</p>
  
  <pre class="lang-ps prettyprint-override"><code>$configRepository = @()
  foreach($attr in ($xml.Configuration.ConfigRepository).attributes)
  {
      $configRepository += @{ $attr.Name = $attr.Value} 
  }
  </code></pre>
  
  <p>When output to JSON, I get something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>"ConfigRepository":  [
      {
          "CacheEnabled":  "true"
      },
      {
          "CacheExpirationDuration": "600"
      },
      {
          "ConnectionTimeout":  "10000"
      },
      {
          "ServiceMonitorPollDuration":  "10"
      },
      {
          "ServiceUri":  "http://somemachine"
      },
  ]     
  </code></pre>
  
  <p><strong>The actual question:</strong></p>
  
  <p>Is there a way to keep my PS code generic, but with an output like this instead?</p>
  
  <pre class="lang-js prettyprint-override"><code>"ConfigRepository":  [
      {
          "CacheEnabled":  "true"
          "CacheExpirationDuration": "600"
          "ConnectionTimeout":  "10000"
          "ServiceMonitorPollDuration":  "10"
          "ServiceUri":  "http://somemachine"
      },
  ]
  </code></pre>