Prerequisites
Summary
ConvertTo-Json produces different JSON output for the same IPAddress value depending on whether it is passed via pipeline or via -InputObject parameter. The pipeline output includes an IPAddressToString property, while the -InputObject output does not.
Steps to reproduce
$ip = [System.Net.IPAddress]::Parse("192.168.1.1")
# Via pipeline
$ip | ConvertTo-Json -Compress
# Via -InputObject parameter
ConvertTo-Json -InputObject $ip -Compress
Expected behavior
# Both methods should produce the same output
"192.168.1.1"
Note: Serializing as a string would require a custom JsonConverter. Similar types (e.g., IPEndPoint, PhysicalAddress) would also need the same treatment, so the scope of this change may be larger than it appears.
Actual behavior
# Via pipeline (includes IPAddressToString)
{"AddressFamily":2,"ScopeId":null,"IsIPv6Multicast":false,"IsIPv6LinkLocal":false,"IsIPv6SiteLocal":false,"IsIPv6Teredo":false,"IsIPv6UniqueLocal":false,"IsIPv4MappedToIPv6":false,"Address":16885952,"IPAddressToString":"192.168.1.1"}
# Via -InputObject (no IPAddressToString)
{"AddressFamily":2,"ScopeId":null,"IsIPv6Multicast":false,"IsIPv6LinkLocal":false,"IsIPv6SiteLocal":false,"IsIPv6Teredo":false,"IsIPv6UniqueLocal":false,"IsIPv4MappedToIPv6":false,"Address":16885952}
Environment data
Name Value
---- -----
PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Prerequisites
Summary
ConvertTo-Jsonproduces different JSON output for the sameIPAddressvalue depending on whether it is passed via pipeline or via-InputObjectparameter. The pipeline output includes anIPAddressToStringproperty, while the-InputObjectoutput does not.Steps to reproduce
Expected behavior
Note: Serializing as a string would require a custom JsonConverter. Similar types (e.g., IPEndPoint, PhysicalAddress) would also need the same treatment, so the scope of this change may be larger than it appears.
Actual behavior
Environment data