Could you just unmarshal it to a map[string]IntTSList, and then walk it and 
build whatever structure you want?

If you want to pick certain fixed fields into a struct and separate out the 
leftovers to be parsed as "subnet[X].Y", then see
https://stackoverflow.com/questions/33436730/unmarshal-json-with-some-known-and-some-unknown-field-names
The last answer points to some other JSON libraries which can handle this 
part for you - but you'd still have to process the "subnet[X].Y" keys.

On Thursday, 14 September 2023 at 16:18:09 UTC+1 Tobias Klausmann wrote:

> Hi! 
>
> On Thu, 14 Sep 2023, Peter Galbavy wrote:
> > You will need to create a custom type and unmarshal method. Plenty of 
> > example if you search for "golang custom json unmarshal".
> > 
> > As I've only had to implement it for a couple of simple types I can't 
> offer 
> > my own valid example.
>
> I am aware of the ability to make custom unmarshalers, but in this
> particular case, I would have to ma an unmarshaler for basically the
> whole JSON - since I cant map all variants of foo[n].something to one
> type/unmarshaler: the stdlib JSON functionality using struct tags does
> not allow fro wildcards/patterns, as far as I can tell, and I don't know
> what range N might be in, so I can't hardcode it.
>
> Best,
> Tobias
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/64c2d808-fcd7-4238-a5d3-187f1f7c6b49n%40googlegroups.com.

Reply via email to