If there is a json tag with multiple fields in a single line, is there any
json parser which will consider the json field name?
Like in below, "encoding/json" ignores the fields to unmarshal if there are
multiple fields in a single line with a json tag.
EX: below code will print nothing.
type a_1_struct_name struct {
Field1, Field2 string `json:"field_1"`
}
func main() {
a := a_1_struct_name{}
j := `{"field_1": "field_1_val"}`
if err := json.Unmarshal([]byte(j), &a); err != nil {
log.Fatal(err)
}
fmt.Println(a)
}
But if we remove the json tag `json:"field_1"` and the change the value of
json(*j*) accordingly, it prints {field_1_val }
I am writing a program to get the json equivalent tag of struct fields
using reflect.
*My question is,* is it safe to ignore the fieldList(*comma separated
struct fields in a single line*) if there is a json tag with it?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/1932cc53-b7b6-44d2-b855-1639e4c32ac0o%40googlegroups.com.