-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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 -CompressExpected 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.0Metadata
Metadata
Assignees
Labels
No labels