title: Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2
body: <p>Why do I get unexpected <a href="https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-6" rel="noreferrer"><code>ConvertTo-Json</code></a> results, why do I get values like <code>System.Collections.Hashtable</code> and/or why does a round-trip (<code>$Json | ConvertFrom-Json | ConvertTo-Json</code>) fail?</p>
  
  <h2>Meta issue</h2>
  
  <p>Stackoverflow has a good mechanism to prevent duplicate <strong>questions</strong> but as far as I can see there is no mechanism to prevent questions that have a duplicate <strong>cause</strong>. Take this question as a an example: almost every week a new question comes in with the same cause, yet it is often difficult to define it as a duplicate because the question itself is just a slightly different.
  Nevertheless, I wouldn't be surprised if this question/answer itself ends up as a duplicate (or off-topic) but unfortunately stackoverflow has no possibility to <a href="https://meta.stackexchange.com/questions/161064/writing-article-instead-of-asking-question">write an article</a> to prevent other programmers from continuing writing questions caused by this “known” pitfall.</p>
  
  <h2>Duplicates</h2>
  
  <p>A few examples of similar questions with the same common cause:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/53562942/powershell-convertto-json-does-not-convert-array-as-expected">PowerShell ConvertTo-Json does not convert Array as expected</a>
  (yesterday)</li>
  <li><a href="https://stackoverflow.com/questions/17929494/powershell-convertto-json-with-embedded-hashtable">Powershell ConvertTo-json with embedded hashtable</a></li>
  <li><a href="https://stackoverflow.com/questions/53287346/powershell-convertto-json-has-messed-json-format-output">powershell “ConvertTo-Json” has messed json format output</a></li>
  <li><a href="https://stackoverflow.com/questions/30929633/nested-arrays-and-convertto-json">Nested arrays and ConvertTo-Json</a></li>
  <li><a href="https://stackoverflow.com/questions/22260343/powershell-convertto-json-missing-nested-level">Powershell ConvertTo-JSON missing nested level</a></li>
  <li><a href="https://stackoverflow.com/questions/22275724/how-to-save-a-json-object-to-a-file-using-powershell">How to save a JSON object to a file using Powershell?</a></li>
  <li><a href="https://stackoverflow.com/questions/38742767/cannot-convert-pscustomobjects-within-array-back-to-json-correctly">Cannot convert PSCustomObjects within array back to JSON correctly</a></li>
  <li><a href="https://stackoverflow.com/questions/42448161/convertto-json-flattens-arrays-over-3-levels-deep">ConvertTo-Json flattens arrays over 3 levels deep</a></li>
  <li><a href="https://stackoverflow.com/questions/53562763/add-an-array-of-objects-to-a-psobject-at-once">Add an array of objects to a PSObject at once</a></li>
  <li><a href="https://stackoverflow.com/questions/53354665/why-does-convertto-json-drop-values">Why does ConvertTo-Json drop values</a></li>
  <li><a href="https://stackoverflow.com/questions/32774889/how-to-round-trip-this-json-to-psobject-and-back-in-powershell">How to round-trip this JSON to PSObject and back in Powershell</a></li>
  <li>…</li>
  </ul>
  
  <h2>Different</h2>
  
  <p>So, were does this “self-answered” question differ from the above duplicates?<br>
  It has the common cause in the title and with that it might better prevent repeating questions due to the same cause.</p>