diff --git a/scalar.go b/scalar.go index c91574c..42bac75 100644 --- a/scalar.go +++ b/scalar.go @@ -74,6 +74,9 @@ type ( // MarshalJSON implements the json.Marshaler interface. // The URI is a quoted string. func (u URI) MarshalJSON() ([]byte, error) { + if u.URL == nil { + return []byte("null"), nil + } return json.Marshal(u.String()) } diff --git a/scalar_test.go b/scalar_test.go index c2b34f0..c7bb450 100644 --- a/scalar_test.go +++ b/scalar_test.go @@ -16,6 +16,11 @@ func TestURI_MarshalJSON(t *testing.T) { in githubv4.URI want string }{ + { + name: "null", + in: githubv4.URI{}, + want: `null`, + }, { in: githubv4.URI{URL: &url.URL{Scheme: "https", Host: "example.org", Path: "/foo/bar"}}, want: `"https://example.org/foo/bar"`,