Documentation
¶
Index ¶
- func Compact(dst *bytes.Buffer, src []byte) error
- func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
- func Marshal(v any, opts ...EncOptsOption) ([]byte, error)
- func MarshalIndent(v any, prefix, indent string, opts ...EncOptsOption) ([]byte, error)
- func Valid(data []byte) bool
- type EmptyEncOptsOption
- type EncOptsOption
- func WithEncOptsEscapeHTML(v bool) EncOptsOption
- func WithEncOptsQuoted(v bool) EncOptsOption
- func WithEncOptsTruncate(v int) EncOptsOption
- func WithEncOptsTruncateArray(v int) EncOptsOption
- func WithEncOptsTruncateBytes(v int) EncOptsOption
- func WithEncOptsTruncateMap(v int) EncOptsOption
- func WithEncOptsTruncateSlice(v int) EncOptsOption
- func WithEncOptsTruncateString(v int) EncOptsOption
- type EncOptsOptionFunc
- type MarshalerError
- type Number
- type SyntaxError
- type UnsupportedTypeError
- type UnsupportedValueError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
Compact appends to dst the JSON-encoded src with insignificant space characters elided.
func Indent ¶
Indent appends to dst an indented form of the JSON-encoded src. Each element in a JSON object or array begins on a new, indented line beginning with prefix followed by one or more copies of indent according to the indentation nesting. The data appended to dst does not begin with the prefix nor any indentation, to make it easier to embed inside other formatted JSON data. Although leading space characters (space, tab, carriage return, newline) at the beginning of src are dropped, trailing space characters at the end of src are preserved and copied to dst. For example, if src has no trailing spaces, neither will dst; if src ends in a trailing newline, so will dst.
func Marshal ¶
func Marshal(v any, opts ...EncOptsOption) ([]byte, error)
Marshal returns the JSON encoding of v, and support truncate.
func MarshalIndent ¶
func MarshalIndent(v any, prefix, indent string, opts ...EncOptsOption) ([]byte, error)
MarshalIndent is like Marshal but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.
Types ¶
type EmptyEncOptsOption ¶
type EmptyEncOptsOption struct{}
EmptyEncOptsOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EncOptsOption ¶
type EncOptsOption interface {
// contains filtered or unexported methods
}
A EncOptsOption sets options.
func WithEncOptsEscapeHTML ¶
func WithEncOptsEscapeHTML(v bool) EncOptsOption
WithEncOptsEscapeHTML sets escapeHTML in encOpts. escapeHTML causes '<', '>', and '&' to be escaped in JSON strings.
func WithEncOptsQuoted ¶
func WithEncOptsQuoted(v bool) EncOptsOption
WithEncOptsQuoted sets quoted in encOpts. quoted causes primitive fields to be encoded inside JSON strings.
func WithEncOptsTruncate ¶
func WithEncOptsTruncate(v int) EncOptsOption
WithEncOptsTruncate sets truncate in encOpts.
func WithEncOptsTruncateArray ¶
func WithEncOptsTruncateArray(v int) EncOptsOption
WithEncOptsTruncateArray sets truncateArray in encOpts.
func WithEncOptsTruncateBytes ¶
func WithEncOptsTruncateBytes(v int) EncOptsOption
WithEncOptsTruncateBytes sets truncateBytes in encOpts.
func WithEncOptsTruncateMap ¶
func WithEncOptsTruncateMap(v int) EncOptsOption
WithEncOptsTruncateMap sets truncateMap in encOpts.
func WithEncOptsTruncateSlice ¶
func WithEncOptsTruncateSlice(v int) EncOptsOption
WithEncOptsTruncateSlice sets truncateSlice in encOpts.
func WithEncOptsTruncateString ¶
func WithEncOptsTruncateString(v int) EncOptsOption
WithEncOptsTruncateString sets truncateString in encOpts.
type EncOptsOptionFunc ¶
type EncOptsOptionFunc func(*encOpts)
EncOptsOptionFunc wraps a function that modifies encOpts into an implementation of the EncOptsOption interface.
type MarshalerError ¶
type MarshalerError struct { Type reflect.Type Err error // contains filtered or unexported fields }
A MarshalerError represents an error from calling a MarshalJSON or MarshalText method.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
func (*MarshalerError) Unwrap ¶
func (e *MarshalerError) Unwrap() error
Unwrap returns the underlying error.
type Number ¶
type Number string
A Number represents a JSON number literal.
type SyntaxError ¶
type SyntaxError struct { Offset int64 // error occurred after reading Offset bytes // contains filtered or unexported fields }
A SyntaxError is a description of a JSON syntax error. Unmarshal will return a SyntaxError if the JSON can't be parsed.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type UnsupportedTypeError ¶
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string