title: Powershell: Compare-object not comparing nested objects
body: <p>or how I stopped worrying and learned to love the string collection</p>
  
  <p>Given the following two json strings:</p>
  
  <pre><code>$jsonString1 = '{ "baz": "quuz", "cow": [ "moo", "CUD" ], "foo": "bar" }'
  $jsonstring2 = '{ "baz": "quuz", "cow": [ "moo", "GRASS" ], "foo": "bar" }'
  </code></pre>
  
  <p>I want to get the differences in the objects they represent</p>
  
  <pre><code>&lt;# First attempt: Convert each to an object, then compare normally #&gt;
  function Compare-Json {
      &lt;# Make powershell objects from each string #&gt;
      $obj1 = $jsonString1 | ConvertFrom-Json
      $obj2 = $jsonstring2 | ConvertFrom-Json
  
      Compare-Object $obj1 $obj2
  }
  
  PS E:\temp&gt; Compare-Json
  
  PS E:\temp&gt; 
  </code></pre>
  
  <p>Yes, that is no output at all. </p>
  
  <p>Current workaround is to convert the json into objects, back to strings, then split the strings and finally compare each collection</p>
  
  <pre><code>function Compare-Json {
      &lt;# Convert to pretty json, then split to make a string array #&gt;
      $obj1 = $($jsonString1 | ConvertFrom-Json | ConvertTo-Json) -split ([Environment]::NewLine)
      $obj2 = $($jsonstring2 | ConvertFrom-Json | ConvertTo-Json) -split ([Environment]::NewLine)
  
      Compare-Object $obj1 $obj2
  }
  
  
  PS E:\temp&gt; Compare-Json
  
  InputObject      SideIndicator                                               
  -----------      -------------                                               
  "GRASS"          =&gt;                                                          
  "CUD"            &lt;=                                                          
  
  PS E:\temp&gt; 
  </code></pre>
  
  <p>Is there a simpler method to deep-compare two objects?</p>