-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ConvertTo-Json unexpectedly serializes AutomationValue.Null as an empty object, not null #9231
Copy link
Copy link
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
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-JsonExpected behavior
{
"foo": null,
"bar": null
}
Actual behavior
{
"foo": {},
"bar": null
}
Environment data
PowerShell Core 6.2.0-rc.1
Windows PowerShell v5.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module