[go-nuts] Newbie How to read unmarshall a varient struct in Json

2017-06-04 Thread Jon Calhoun
See the last section of this article where it talks about generics - https://blog.gopheracademy.com/advent-2016/advanced-encoding-decoding/ It isn't exactly what you are doing but the same idea should work in your use case. The encoding/decoding code becomes longer but it makes using the data s

[go-nuts] Newbie How to read unmarshall a varient struct in Json

2017-06-03 Thread Amnon Baron Cohen
If I need to read some json which could be { "tag": "number", "value": 1 } or { "tag": "object", "value": { "a": 1, "b": 2 } } what is the best way to unmarshall it? I could unmarshall into struct { Tag string Val interface{} } But once I have read the d