Prettify json in powershell 3

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

    If you really don't want to go down the simplest route, which is to use inbuilt PowerShell functions | ConvertFrom-Json | ConvertTo-Json, here is another method, using JSON.net

    # http://james.newtonking.com/projects/json-net.aspx
    Add-Type -Path "DRIVE:\path\to\Newtonsoft.Json.dll"
    
    $jsonString = '{ "baz": "quuz", "cow": [ "moo", "cud" ], "foo": "bar" }'
    [Newtonsoft.Json.Linq.JObject]::Parse($jsonString).ToString()
    

提交回复
热议问题