prettyjson

package
v1.2.70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compact

func Compact(dst *bytes.Buffer, src []byte) error

Compact appends to dst the JSON-encoded src with insignificant space characters elided.

func Indent

func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error

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.

func Valid

func Valid(data []byte) bool

Valid reports whether data is a valid JSON encoding.

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.

func (Number) Float64

func (n Number) Float64() (float64, error)

Float64 returns the number as a float64.

func (Number) Int64

func (n Number) Int64() (int64, error)

Int64 returns the number as an int64.

func (Number) String

func (n Number) String() string

String returns the literal text of the number.

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

type UnsupportedTypeError struct {
	Type reflect.Type
}

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError

type UnsupportedValueError struct {
	Value reflect.Value
	Str   string
}

An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL