Inspired by this post I created a JsonString type. It will decode any string, number, boolean or null values to a string.
https://play.golang.org/p/ucAxwriL2K
type JsonString string type jsonString JsonString func (st *JsonString) UnmarshalJSON(bArr []byte) (err error) { j, n, f, b := jsonString(""), uint64(0), float64(0), bool(false) if err = json.Unmarshal(bArr, &j); err == nil { *st = JsonString(j) return } if err = json.Unmarshal(bArr, &n); err == nil { *st = JsonString(string(bArr[:])) return } if err = json.Unmarshal(bArr, &f); err == nil { *st = JsonString(string(bArr[:])) return } if err = json.Unmarshal(bArr, &b); err == nil { *st = JsonString(string(bArr[:])) return } return }
json.Numbertype is only used if you useDecoder.UseNumber(), I think. Otherwise it is just stored asfloat64and the problem is that huge numbers can't properly stored this way (that's why thejson.Numbertype exists). See attilaolah.eu/2013/11/29/json-decoding-in-go/…