-
Notifications
You must be signed in to change notification settings - Fork 8.3k
ConvertTo-Json doesn't serialize $null #10942
Copy link
Copy link
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Conceptually related: #9231
Null values are a legitimate part of JSON, so
ConvertTo-Jsonshould be able to serialize them.Currently,
ConvertTo-Jsonquietly ignores$nulls as a distinct input objects (but does serialize them correctly as a property values).Steps to reproduce
Expected behavior
All tests should pass.
Actual behavior
The
$nulltests fail:That is, instead of returning string
'null', there was no output.Update: To clarify:
$nullis generally ignored, so the following test fails too, because it returns'[1,2]', not'[1,null,2]':Environment data