4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PowerShellでJSONを整形

Posted at

#使い所

  • PowerAutomateで出力されたフラットなjsonを整形して確認したい。
  • 職場でEdgeしか使えない。 →Firefoxなら勝手に整形してくれる。
  • VSCodeは使えない環境。
  • jsonはアカウント情報を含んでおりオンラインツールはやめておきたい。

image.png

・デスクトップに置いたjson-min.txt内にjsonを貼り付けるか、フラットなjson直接貼り付ける。

json整形
$_defaultJsonPath = "$home\Desktop\json-min.txt"

$file_or_json = Read-Host "フラットjsonかファイルパスを入力して下さい。"

if($file_or_json -eq ""){
    if((Test-Path $_defaultJsonPath) -eq $false){
        Write-Host "ファイルが見つかりません。"
        return
    }

    $file_or_json = $_defaultJsonPath    
}


if((Test-Path $file_or_json) -eq $true){
    (Get-Content -Path $file_or_json -Encoding UTF8) | ConvertFrom-Json | ConvertTo-Json -Depth 100 | Set-Content $file_or_json -Encoding UTF8
    Write-Host "整形が完了しました。:" (Split-Path $file_or_json -Leaf)

}else{
    $prettyJson = $file_or_json | ConvertFrom-Json | ConvertTo-Json -Depth 100
    Write-Host $prettyJson
}

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?