How to get the json field names of a struct in golang?
<p>What is the way to get the json field names of this struct ?</p>

<pre><code>type example struct {
    Id          int `json:"id"`
    CreatedAt   string `json:"created_at"`
    Tag         string `json:"tag"`
    Text        string `json:"text"`
    AuthorId    int `json:"author_id"`
}
</code></pre>

<p>I try to print the fields with this function :</p>

<pre><code>func (b example) PrintFields() {
    val := reflect.ValueOf(b)
    for i := 0; i &lt; val.Type().NumField(); i++ {
        fmt.Println(val.Type().Field(i).Name)
    }
}
</code></pre>

<p>Of course I get :</p>

<pre><code>Id
CreatedAt
Tag
Text
AuthorId
</code></pre>

<p>But I would like something like :</p>

<pre><code>id
created_at
tag
text
author_id
</code></pre>