1

like

type User struct {
    ID       int32     `json:"_id"` 
    Week     string    `json:"week"`         
}

json.Marshal(&User{},true)//omitempty is true

will return

{}

is bson,yaml,sql or any other library support this feature?

3
  • No, but you can use a tool like github.com/fatih/gomodifytags to modify the types in your source code easily. Commented Aug 1, 2019 at 12:30
  • the thing is that I accept an object, do some processing, and then hand the object to json,there is no way that I can edit the original struct. Commented Aug 1, 2019 at 12:48
  • You can copy the original type and then modify the tags. To guarantee compatibility if the original changes, add a type conversion from the original to your type somewhere. Commented Aug 1, 2019 at 15:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.