title: Why does powershell give different result in one-liner than two-liner when converting JSON?
body: <h1>Overview</h1>
  
  <p>From a powershell 3 prompt,, I want to call a RESTful service, get some JSON, and pretty-print it. I discovered that if I convert the data to a powershell object, and then convert the powershell object back to json, I get back a nice pretty-printed string. However, if I combine the two conversions into a one-liner with a pipe I will get a different result.</p>
  
  <p><strong>TL;DR:</strong> this:</p>
  
  <pre><code>PS&gt; $psobj = $orig | ConvertFrom-JSON
  PS&gt; $psobj | ConvertTo-JSON
  </code></pre>
  
  <p>... gives me different result than this:</p>
  
  <pre><code>PS&gt; $orig | ConvertFrom-JSON | ConvertTo-JSON
  </code></pre>
  
  <h1>Original data</h1>
  
  <pre><code>[
    {
      "Type": "1",
      "Name": "QA"
    },
    {
      "Type": "2",
      "Name": "whatver"
    }
  ]
  </code></pre>
  
  <h1>Doing the conversion in two steps</h1>
  
  <p>I'm going to remove the whitespace (so it fits on one line...), convert it to a powershell object, and then convert it back to JSON. This works well, and gives me back the correct data:</p>
  
  <pre><code>PS&gt; $orig = '[{"Type": "1","Name": "QA"},{"Type": "2","Name": "DEV"}]'
  PS&gt; $psobj = $orig | ConvertFrom-JSON
  PS&gt; $psobj | ConvertTo-JSON
  [
      {
          "Type":  "1",
          "Name":  "QA"
      },
      {
          "Type":  "2",
          "Name":  "DEV"
      }
  ]
  </code></pre>
  
  <h1>Combining the two steps with a pipe</h1>
  
  <p>However, if I combine those last two statements into a one-liner, I get a different result:</p>
  
  <pre><code>PS&gt; $orig | ConvertFrom-JSON | ConvertTo-JSON
  {
      "value":  [
                    {
                        "Type":  "1",
                        "Name":  "QA"
                    },
                    {
                        "Type":  "2",
                        "Name":  "DEV"
                    }
                ],
      "Count":  2
  }
  </code></pre>
  
  <p>Notice the addition of the keys "value" and "Count". Why is there a difference? I'm sure it has something to do with the desire to return JSON object rather than a JSON array, but I don't understand why the way I do the conversion affects the end result. </p>