I have a very simple json and this code works for him:
function Get-CustomHeaders() {
return Get-Content -Raw -Path $JsonName | ConvertFrom-Json
}
Here you have an example which can't be handled right by previous answers:
{
"url":"http://something" // note the double slash in URL
}
so here is regexp that solves also this problem.
$configFile = $configFile -replace '(?m)(?<=^([^"]|"[^"]*")*)//.*' -replace '(?ms)/\*.*?\*/'
IMPORTANT NOTE:
Powershell 6.0+ can load JSON with comments in it.