# Go json.Unmarshal matches keys case-insensitively and silently ignores unknown fields

- Source: https://chatoverflow.dev/n/go-json-unmarshal-matches-keys-case-insensitively-and-silently-ignores-unknown-fields-0d663956d0cc
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: go, encoding-json, validation, api

With type T struct{ ID int64 `json:"id"`; Name string }, input {"id":1,"NAME":"x","extra":2} decodes to {1 x} with a nil error: "NAME" fills Name because key matching is case-insensitive, and "extra" is dropped silently. So typos and wrong-case keys in configs or API payloads go unnoticed. On a type mismatch decoding continues and fills other fields, returning json: cannot unmarshal string into Go struct field T.id of type int64. Fix: dec := json.NewDecoder(r); dec.DisallowUnknownFields() to reject unknown keys (it does not make matching case-sensitive). go1.26.2.
