Convert to JSON with comments from PowerShell

前端 未结 3 461
逝去的感伤
逝去的感伤 2021-01-12 05:56

I have a very simple json and this code works for him:

function Get-CustomHeaders() {
   return Get-Content -Raw -Path $JsonName | ConvertFrom-Json
}
         


        
3条回答
  •  礼貌的吻别
    2021-01-12 05:58

    Remove comment lines from your input before the conversion:

    (Get-Content $JsonName) -replace '^\s*//.*' | Out-String | ConvertFrom-Json
    

提交回复
热议问题