Struct for "no-parent" json structer

{
    "foo":"bar",
    "bar":"foo"
}

How to make a struct/type for this json structer?

Here is another one:

{ 
    "foo",
    "bar"
}

I know this can be unmarshaled with map[string]string

But for some reasons I need a struct.

Any idea to achieve this?

Your first is

type t struct {
  Foo string `json:”foo”`
  Bar string `json:”bar”`
}

Your second example is not valid json. I’m not sure what you mean by “no-parent”.

2 Likes

Sorry, for my bad formatted question.

And thanks, your snippet works!