From 71e9337bdba5f9e7ea9c8bb10ccfce0aa9cbd827 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 30 Jan 2026 10:09:17 -0800 Subject: [PATCH] Omit empty ips arrays from interface JSON Co-Authored-By: Claude Opus 4.5 --- types.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index db5a2f0..c5c8b04 100644 --- a/types.go +++ b/types.go @@ -354,10 +354,29 @@ func (m InterfaceMap) MarshalJSON() ([]byte, error) { type Interface struct { Name string `json:"name,omitempty"` MAC MAC `json:"mac"` - IPs IPSet `json:"ips"` + IPs IPSet `json:"ips,omitempty"` Stats *InterfaceStats `json:"stats,omitempty"` } +func (i *Interface) MarshalJSON() ([]byte, error) { + type ifaceJSON struct { + Name string `json:"name,omitempty"` + MAC MAC `json:"mac"` + IPs []string `json:"ips,omitempty"` + Stats *InterfaceStats `json:"stats,omitempty"` + } + var ips []string + if len(i.IPs) > 0 { + ips = i.IPs.Slice() + } + return json.Marshal(ifaceJSON{ + Name: i.Name, + MAC: i.MAC, + IPs: ips, + Stats: i.Stats, + }) +} + type InterfaceStats struct { Speed uint64 `json:"speed,omitempty"` InErrors uint64 `json:"in_errors,omitempty"`