Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Marshal fails when we define struct variables in lower case: go version go1.4. #11926

Closed
nzsrini opened this issue Jul 30, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@nzsrini
Copy link

commented Jul 30, 2015

package main

import (
"encoding/json"
"fmt"
"os"
)

func main() {

type MilvariableStartswithUpperCase struct {
    Id  int64  `json:"id"` //sss
    Cty string `json:"firstname"`
}

type MilvariableStartswithLowerCase struct {
    id  int64
    cty string
}

upperCase := MilvariableStartswithUpperCase{1, "UpperCase"}
lowerCase := MilvariableStartswithLowerCase{1, "Lowercase"}

marshalsucessfull, err := json.Marshal(upperCase)
if err != nil {
    fmt.Println("error:", err)
}

marshalunsucessfull, err := json.Marshal(lowerCase)
if err != nil {
    fmt.Println("error:", err)
}

fmt.Println("----")
fmt.Println("Marshal Sucess")
os.Stdout.Write(marshalsucessfull)
fmt.Println()
fmt.Println("Marshal Failed.")
os.Stdout.Write(marshalunsucessfull)

}

Out Put
Marshal Sucess
{"id":1,"firstname":"UpperCase"}
Marshal Failed.
{}____

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 30, 2015

As far as I can see, this is working as expected. The docs for encoding/json say that each exported struct field becomes a member of the object. Non-exported fields do not.

@mikioh mikioh changed the title Marshal Fails when we define struct variables in lower case: go version go1.4. encoding/json: Marshal fails when we define struct variables in lower case: go version go1.4. Jul 30, 2015

@golang golang locked and limited conversation to collaborators Aug 5, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.