param (
[Parameter(Mandatory = $true)]
[string]$InputFile,
[Parameter(Mandatory = $true)]
[string]$OutputFile,
# JSON整形 / JSON文字列
[ValidateSet("json_format", "json_string")]
[string]$Mode = "json_format",
# ネスト深さ対策
[int]$Depth = 100
)
if (-not (Test-Path $InputFile)) {
Write-Error "Input file not found: $InputFile"
exit 1
}
try {
$json = Get-Content $InputFile -Raw
$obj = $json | ConvertFrom-Json
if ($Mode -eq "json_format") {
$out = $obj | ConvertTo-Json -Depth $Depth
} else {
$out = $obj | ConvertTo-Json -Depth $Depth -Compress
}
Set-Content $OutputFile $out
}
catch {
Write-Error "JSON parse failed: $($_.Exception.Message)"
exit 2
}