Prettify json in powershell 3

后端 未结 5 1393
清酒与你
清酒与你 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:13

    Works for me. Parentheses make sure get-content is done before piping. Default depth of convertto-json is 2, which is often too low.

    function pjson ($jsonfile) {
      (get-content $jsonfile) | convertfrom-json | convertto-json -depth 100 | 
        set-content $jsonfile
    }
    

提交回复
热议问题