Parsing JSON in Golang doesn't Populate Object


As part of an Oauth application, I need to decode some JSON. But I cannot get the object populated. There is no failure, but the data just isn’t there. I’ve tried a bunch of different ways…

I have recreated the problem at

import (

type RefreshTokenData struct {
    id            string `json:"id"`
    issued_at     string `json:"issued_at"`
    scope         string `json:"scope"`
    instance_url  string `json:"instance_url"`
    token_type    string `json:"token_type"`
    refresh_token string `json:"refresh_token"`
    signature     string `json:"signature"`
    access_token  string `json:"access_token"`

func main() {
    var tokenResp = `
    "scope":"full refresh_token",

    var tokenData RefreshTokenData
    decoder := json.NewDecoder(strings.NewReader(tokenResp))
    if jsonerr := decoder.Decode(&tokenData); jsonerr != nil {
        fmt.Println("****Failed to decode json")
    } else {
        fmt.Println("****Refresh token: " + tokenData.refresh_token)


The JSON encoding package works with exported fields only. Capitalize the field names to export them:

type RefreshTokenData struct {
  Id            string `json:"id"`
  Issued_at     string `json:"issued_at"`
  Scope         string `json:"scope"`
  Instance_url  string `json:"instance_url"`
  Token_type    string `json:"token_type"`
  Refresh_token string `json:"refresh_token"`
  Signature     string `json:"signature"`
  Access_token  string `json:"access_token"`

playground example

Answered By – Bayta Darell

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.