0

I'm learning GO and when defining structs for working with JSON like below.

type List struct {
    ID   string `datastore:"-"`
    Name string
}

I see that there is this text in between ` sign. I have not been able to find an explanation what that signifies.

Things seem to work even without those.

1
  • This question is a duplicate, but this question has better wording. Commented Aug 16, 2018 at 12:45

1 Answer 1

3

They are struct tags used in Marshal'ing Go struct into JSON. In JSON, unlike Go, fields are in lowercase strings. Therefore, most use cases would be

type List struct {
    ID   string `json:"id"`
    Name string `json:"name"`
}

In JSON

{
  "id": "some id",
  "name": "some name"
}

See post here

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry it's actually "struct tags". Edited!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.