Proposals Unofficial Go proposal tracker

Add text marshaling to HardwareAddr and IPMask

#29678 · net · medium impact · Implemented in Go 1.28 ·

net.HardwareAddr and net.IPMask are byte slices without text marshaling methods. Because of this, encoding/json encodes them as base64 and can't decode readable strings like "ab:cd:ef:ab:cd:ef". net.IP already marshals to readable text, so this behavior is inconsistent.

The proposal adds MarshalText and UnmarshalText methods to HardwareAddr and IPMask. UnmarshalText accepts both the old base64 form and the readable form, whatever the setting. MarshalText produces the readable form only when GODEBUG=netmarshal=1 is set. HardwareAddr uses its String output. IPMask is formatted as an IP address, such as 255.255.255.0, because IPMask.String output can look like base64. At first, netmarshal defaults to off, so the output stays base64. At least two releases later, the default flips to readable output. IPNet is not included.

var v struct{ MAC net.HardwareAddr }
json.Unmarshal([]byte(`{"MAC":"ab:cd:ef:ab:cd:ef"}`), &v) // now works
Proposal
#29678 by maja42
Status
Implemented on Oct 14, 2026
Release
Go 1.28
Impact
medium
Area
net