You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertTo-Json unexpectedly serializes AutomationValue.Null as an empty object, not null #9231
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
Activity
vexx32 commentedon Mar 26, 2019
cc Mark Kraus (@markekraus)
This is... weird lol.
cawoodm commentedon Mar 26, 2019
Also
. {}is equal (-eq) to$nullbut doesn't serialize tonull.markekraus commentedon Mar 27, 2019
heh.. that's a fun one... we may need to create a custom JSON handler for AutomationNull or something.