How to get a JSON name of a field? #1204
-
error.Field() does not seem to work properly, just gives me the StructField() unless I do RegisterTagNameFunc. Is there any way to do it natively since in the docs it says Field should do this? Am I missing something? struct Something {
Field string `json:"field" validate:"required"`
}
validator.Struct(something)
err.Field() => "Field" I must be missing something right? docs say that FIeld() gives me Cheers and thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The document does not say it will return the JSON name of the field, it is used as an example only and clearly states it will use the field(structs) field name unless overridden with the tag name function see https://github.com/go-playground/validator/blob/master/errors.go#L118 It is working as intended. I am assuming you are referring to the Go documentation. |
Beta Was this translation helpful? Give feedback.
The document does not say it will return the JSON name of the field, it is used as an example only and clearly states it will use the field(structs) field name unless overridden with the tag name function see https://github.com/go-playground/validator/blob/master/errors.go#L118
It is working as intended.
I am assuming you are referring to the Go documentation.