Private/Utils/Format-Json.ps1
function Format-Json { param ( [Parameter(Mandatory, ValueFromPipeline) ][String] $json ) $nl = [Environment]::NewLine $indent = 0; ($json -Split $nl | Foreach-Object { if ($_ -match '[\}\]]') { # This line contains ] or }, decrement the indentation level $indent-- } $line = (' ' * $indent * 2) + $_.TrimStart().Replace(': ', ': ') if ($_ -match '[\{\[]') { # This line contains [ or {, increment the indentation level $indent++ } $line }) -Join $nl } |