Documentation
¶
Overview ¶
Package jsonenc encodes values as encoding/json does, byte for byte, except that a nil slice is written as [] instead of null: Tern sends [] for pages, typed endpoints and live components, so their TypeScript types are T[] rather than T[] | null.
It's faster than encoding/json followed by a copy that fills in nil slices: each type's encoder is built once, and nothing is copied. Values that encode themselves (json.Marshaler, encoding.TextMarshaler) and the rare struct tag options it doesn't implement go through encoding/json.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodesItself ¶ added in v1.8.0
EncodesItself reports whether values of t are written by their own MarshalJSON or MarshalText, or need encoding/json for another reason: what this package hands to encoding/json.
Types ¶
type Field ¶ added in v1.8.0
type Field struct {
Name string
// Index is the path to the field through embedded structs.
Index []int
Type reflect.Type
OmitEmpty bool
OmitZero bool
}
Field is a struct field as encoding/json writes it, for other encoders that follow its rules.
type Verbatim ¶
type Verbatim []byte
Verbatim is JSON this package wrote, written again as it is: no checking, compacting or escaping. Only for its own output, which is already compact and safe to inline in HTML.
func (Verbatim) MarshalJSON ¶
MarshalJSON is for encoding/json, which checks and compacts it.
func (*Verbatim) UnmarshalJSON ¶
UnmarshalJSON keeps the raw JSON, as json.RawMessage does.