title: Converting JSON to PowerShell object and converting PowerShell back to JSON
body: <p>I am exporting the JSON from an Azure Resource Group to a JSON file like this:</p>
  
  <pre><code>Export-AzureRmResourceGroup -ResourceGroupName $SourceResourceGroupName -Path $filename
  </code></pre>
  
  <p>Then I am getting the JSON contents of the file, then applying it to a variable:</p>
  
  <pre><code>$SourceJSON = Get-Content $filename -Raw 
  </code></pre>
  
  <p>I then want to turn (convert) this into a PowerShell object:</p>
  
  <pre><code>$SourceJSONRG = $SourceJSON | ConvertFrom-Json 
  </code></pre>
  
  <p>I then have a look at the resources from with the object:</p>
  
  <pre><code>$SourceJSONRG.resources
  </code></pre>
  
  <p>But the <code>storageProfile</code> section is blank:</p>
  
  <p><a href="https://i.stack.imgur.com/B5moa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B5moa.png" alt="enter image description here"></a></p>
  
  <p>Whereas looking at the JSON (<code>$SourceJSON</code>) in comparison, the <code>storageProfile</code> is not blank: </p>
  
  <p><a href="https://i.stack.imgur.com/GQ5NW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GQ5NW.png" alt="enter image description here"></a></p>
  
  <p>I have tried using the <code>Format-Custom -Depth</code> option to go down much deeper:</p>
  
  <pre><code>$SourceJSONRG = $SourceJSON | ConvertFrom-Json
  $SourceJSONRG = $SourceJSONRG | Format-Custom -Depth 99
  </code></pre>
  
  <p>But this puts in “<code>class PSCustomObject</code>” everywhere which I don’t want.</p>
  
  <p><a href="https://i.stack.imgur.com/65htR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/65htR.png" alt="enter image description here"></a></p>
  
  <p>The ultimate thing I am trying to do here is convert the JSON to a PowerShell object, make changes to it e.g. change the the URI for a disk, then convert back to JSON to use it for deployment to Azure. In other words, converting the JSON to a PowerShell object makes it much easier for me to work with it.</p>
  
  <pre><code>New-AzureRmResourceGroupDeployment -ResourceGroupName $TargetResourceGroupName -TemplateFile "C:\Users\marc\AppData\Local\Temp\test20692192.json"
  </code></pre>