diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go index 3ee2b8b6..5cd1e907 100644 --- a/btcjson/chainsvrresults.go +++ b/btcjson/chainsvrresults.go @@ -385,6 +385,9 @@ func (h *StringOrArray) UnmarshalJSON(data []byte) error { } switch v := unmarshalled.(type) { + case nil: + *h = nil + case string: *h = []string{v} diff --git a/btcjson/chainsvrresults_test.go b/btcjson/chainsvrresults_test.go index fb681a9c..f37adb4b 100644 --- a/btcjson/chainsvrresults_test.go +++ b/btcjson/chainsvrresults_test.go @@ -350,6 +350,16 @@ func TestGetBlockChainInfoWarnings(t *testing.T) { result: `{"warnings": []}`, expected: btcjson.StringOrArray{}, }, + { + name: "blockchain info with null warnings", + result: `{"warnings": null}`, + expected: nil, + }, + { + name: "blockchain info with warnings field omitted", + result: `{}`, + expected: nil, + }, } for _, test := range tests {