diff --git a/routing/http/types/record_bitswap.go b/routing/http/types/record_bitswap.go index 5e49c81658..0780fc3eb2 100644 --- a/routing/http/types/record_bitswap.go +++ b/routing/http/types/record_bitswap.go @@ -28,7 +28,7 @@ type BitswapRecord struct { Schema string Protocol string ID *peer.ID - Addrs []Multiaddr + Addrs []Multiaddr `json:",omitempty"` } func (br *BitswapRecord) GetSchema() string { diff --git a/routing/http/types/record_peer.go b/routing/http/types/record_peer.go index ff4704eb39..76bd810e07 100644 --- a/routing/http/types/record_peer.go +++ b/routing/http/types/record_peer.go @@ -64,9 +64,18 @@ func (pr PeerRecord) MarshalJSON() ([]byte, error) { m[key] = val } } + + // Schema and ID must always be set. m["Schema"] = pr.Schema m["ID"] = pr.ID - m["Addrs"] = pr.Addrs - m["Protocols"] = pr.Protocols + + if pr.Addrs != nil { + m["Addrs"] = pr.Addrs + } + + if pr.Protocols != nil { + m["Protocols"] = pr.Protocols + } + return drjson.MarshalJSONBytes(m) }