PowerShell commands that output nothing output the special [System.Management.Automation.Internal.AutomationNull]::Value singleton, which typically behaves like $null.
Unexpectedly, ConvertTo-Json doesn't treat it as $null, but treats it as an empty object, which is undesired.
Steps to reproduce
# Note: `. {}` yields the [System.Management.Automation.Internal.AutomationNull]::Value
# singleton, not $null.
[pscustomobject] @{ foo = . {}; bar = $null } | ConvertTo-Json
Expected behavior
{
"foo": null,
"bar": null
}
Actual behavior
{
"foo": {},
"bar": null
}
Environment data
PowerShell Core 6.2.0-rc.1
Windows PowerShell v5.1
PowerShell commands that output nothing output the special
[System.Management.Automation.Internal.AutomationNull]::Valuesingleton, which typically behaves like$null.Unexpectedly,
ConvertTo-Jsondoesn't treat it as$null, but treats it as an empty object, which is undesired.Steps to reproduce
Expected behavior
Actual behavior
Environment data