1

I have a JSON that is as follows

{
  "Key1": "Value1",
  "Key2": "Value2",
  "Key3": {
    "InnerKey1": "InnerValue1",
    "InnerKey2": "InnerValue2",
    ...
  }
}

The problem I have is with the Key3 structure which contains a key value of variable length. It is possible that the client sends me another key. How do I create a struct for this in Go

1 Answer 1

1

You can use json2go. For the variable part you could use a map

And you get:

type AutoGenerated struct {
    Key1 string `json:"Key1"`
    Key2 string `json:"Key2"`
    Key3 map[string]string `json:"Key3"`
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.