Documentation
¶
Overview ¶
Package jsonfields finds the fields encoding/json reads from a JSON object into a Go struct. The schema package describes them and the strict decoder checks arguments against them, so a schema and its decoder agree on every name and on which fields are required.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
Name string
Tagged bool // the name came from a json tag
Index []int // the field's index path from the outer struct
Field reflect.StructField
Type reflect.Type // the field's type, with an unnamed pointer followed
Optional bool // ",omitempty" or ",omitzero"
Quoted bool // ",string" on a string, number, or boolean field
// ViaUnexportedPtr names the unexported struct type of an embedded pointer on the field's
// path, if any: encoding/json cannot allocate it, so decoding the field fails.
ViaUnexportedPtr string
}
Field is one field encoding/json reads from a JSON object into a struct.
func Of ¶
Of returns the fields encoding/json reads for struct type t, in index order. It is a port of encoding/json's typeFields: a breadth-first walk over embedded structs, then Go's dominance rules (the shallowest name wins, a json tag breaks a tie at one depth, and any other tie removes the name). A json tag name encoding/json does not accept is a *TagNameError.
type TagNameError ¶
type TagNameError struct {
Struct reflect.Type
Field string // the Go field name
Name string // the tag name
}
TagNameError reports a json tag name encoding/json does not accept (one with a quote, a backslash, or another reserved character). encoding/json v1 falls back to the Go name there and its v2 implementation reads the name differently, so the field has no one JSON name.
func (*TagNameError) Error ¶
func (e *TagNameError) Error() string
Error names the struct, the field and the rejected tag name.