JSON Unmarshal struct case-sensitively

前端 未结 1 847
-上瘾入骨i
-上瘾入骨i 2021-01-17 09:35

Is there any way to make json.Unmarshal not accept a case-insensitive match? I receive a JSON with tags such as \"e\" and \"E\" and would like to unmarshal the obje

1条回答
  •  隐瞒了意图╮
    2021-01-17 10:18

    Unfortunately this is not something currently supported by the standard json library.

    According to https://golang.org/pkg/encoding/json/#Unmarshal

    Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match

    There is no way to turn this behaviour off.

    0 讨论(0)
提交回复
热议问题