You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 15, 2025. It is now read-only.
jsoniter.Unmarshal incorrectly sets pre-initialized map[string]any to nil when input begins with letter "n" #720
When unmarshaling into a pre-initialized map[string]any, if the input starts with the letter n, jsoniter.Unmarshal unexpectedly sets the map to nil.
This happens even when the input is not valid JSON (nan, none, nil, notjson...).
This behavior causes runtime panics such as:
panic: assignment to entry in nil map
because after unmarshaling, the map is unexpectedly nil.
This does not happen with Go’s standard encoding/json for invalid JSON input (standard json returns an error but does not overwrite the map).
To Reproduce
package main
import (
"fmt"
jsoniter "github.com/json-iterator/go"
)
funcmain() {
data:=map[string]any{} // pre-initialized mapinput:= []byte("none") // starts with 'n' but not valid JSONerr:=jsoniter.Unmarshal(input, &data)
fmt.Println("error:", err)
fmt.Println("is nil:", data==nil) // ❌ becomes nil unexpectedlydata["a"] =1// ❌ panic: assignment to entry in nil map
}
Expected behavior
If the input is invalid JSON (e.g., "none", "nan", "nil", "notjson"),
Unmarshal should return an error without modifying the existing map.
A pre-initialized map should never be overwritten with nil unless the input is literally JSON null.
This is how encoding/json behaves.
Actual behavior
For any input beginning with n, jsoniter attempts partial parsing and sets the target map to nil.
This breaks existing Go code that assumes a pre-initialized map remains non-nil after a failed unmarshal.
Activity
fix: prevent map from being set to nil on invalid null-like input