Prettify json in powershell 3

后端 未结 5 1413
清酒与你
清酒与你 2020-12-03 04:43

Given a standard json string value:

$jsonString = \'{ \"baz\": \"quuz\", \"cow\": [ \"moo\", \"cud\" ], \"foo\": \"bar\" }\'

How can I get

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 05:03

    I put this in my profile

    function PrettyPrintJson {
        param(
            [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
            $json
        )
        $json | ConvertFrom-Json | ConvertTo-Json -Depth 100
    }
    

    Which works with pipes, and can be auto-completed, so it's at least somewhat less typing:

    cat .\file.json | PrettyPrintJson
    curl https://api.twitter.com/1.1/statuses/user_timeline.json | PrettyPrintJson
    

提交回复
热议问题