[go-nuts] Re: json unmarshalling troubles

2021-06-03 Thread natxo....@gmail.com
hi all, thanks for your insights. The Value interface{} type does work nicely. I had tried as well the map[string]interface{} route, and it works as well, so now I have two solutions which is kind of a luxury position. Regards, Natxo On Thursday, June 3, 2021 at 7:41:21 AM UTC+2 Amnon wrote

[go-nuts] Re: json unmarshalling troubles

2021-06-02 Thread Amnon
No, whoever designed the schema of this API has lost their marbles, (or lacks any kind of consideration for the unfortunate souls who need to use this API). Unmarshalling a value whose type is not fixed is a pain in Go. But handling a value of unknown type will be a headache in any language. O

[go-nuts] Re: json unmarshalling troubles

2021-06-02 Thread Robert Glonek
I think I'm loosing my marbles. Nevermind what I said. On Wednesday, 2 June 2021 at 16:22:34 UTC+1 Brian Candler wrote: > > If you try using switch value.(type) instead of using reflect, bool will > be reported as int, fyi, so using reflect here. > > Could you explain that a bit further please?

[go-nuts] Re: json unmarshalling troubles

2021-06-02 Thread Brian Candler
> If you try using switch value.(type) instead of using reflect, bool will be reported as int, fyi, so using reflect here. Could you explain that a bit further please? A type switch seems to work OK for me, with no reflect. https://play.golang.org/p/TBH5zKYnG4G -- You received this message be

[go-nuts] Re: json unmarshalling troubles

2021-06-02 Thread Robert Glonek
Here's a quick-glued reflect example. https://play.golang.org/p/blpmIVKhuc4 If you try using switch value.(type) instead of using reflect, bool will be reported as int, fyi, so using reflect here. On Wednesday, 2 June 2021 at 16:02:36 UTC+1 Robert Glonek wrote: > The json is not very strict, w

[go-nuts] Re: json unmarshalling troubles

2021-06-02 Thread Robert Glonek
The json is not very strict, while go is. It would be good if the json struct could potentially be strictly of same type all over the place. Implementing parser for this json in any language will be a bit of a pain with some try/except... If you really need to do so, you would need to have the