How should the @lang field be saved using JSON (with the Go package)?

let’s say you have the following struct:

type User struct {
  UID string `json:"uid,omitmepty"`
  Name string `json:"name,omitmepty"`
}

where you have the following schema:

Schema: `
  name: string @lang .
`

I’m guessing json:"name,omitempty" should be changed to json:"name@en,omitempty"? If so, would it be advised to use the following struct:

type User struct {
  UID string `json:"uid,omitmepty"`
  NameEn string `json:"name@en,omitmepty"`
  NameRu string `json:"name@ru,omitmepty"`
  // NameETC..
}

?

Using mutation in JSON you can simply use <"predicate + @ + Lang">

e.g in JSON format:

{
    "set": [
        {
            "name@en": "english",
            "name@ru": "Russian",
            "TEST": "X"
        },
        {
            "name": "Amit",
            "name@ru": "Russian"
        }
    ]
}

I’m not sure about this below, I’m using https://mholt.github.io/json-to-go/

type AutoGenerated struct {
	NameEn string `json:"name@en"`
	NameRu string `json:"name@ru"`
	TEST   string `json:"TEST"`
}

# whole array
type AutoGenerated []struct {
	NameEn string `json:"name@en,omitempty"`
	NameRu string `json:"name@ru"`
	TEST   string `json:"TEST,omitempty"`
	Name   string `json:"name,omitempty"`
}
1 Like

Thanks a lot, appreciate the fast reply (:

I use that website as well, it’s really amazing

1 Like