json

package
v0.0.0-...-1f4ee57 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: "  ", SortKeys: false}

DefaultOptions is the default options for pretty formats.

View Source
var WithPrivateField = jsoniter.Config{
	IndentionStep:                 4,
	MarshalFloatWith6Digits:       true,
	EscapeHTML:                    true,
	SortMapKeys:                   true,
	UseNumber:                     true,
	ObjectFieldMustBeSimpleString: true,
}.Froze()

Functions

func Color

func Color(src []byte, style *Style) []byte

Color will colorize the json. The style parma is used for customizing the colors. Passing nil to the style param will use the default TerminalStyle.

func Marshal

func Marshal(v interface{}) ([]byte, error)

func NewDecoder

func NewDecoder(r io.Reader) *json.Decoder

func NewEncoder

func NewEncoder(r io.Writer) *json.Encoder

func NewJSONEncoder

func NewJSONEncoder(cfg *encoding.EncoderConfig) encoding.Encoder

NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder appropriately escapes all field keys and values.

Note that the encoder doesn't deduplicate keys, so it's possible to produce a message like

{"foo":"bar","foo":"baz"}

This is permitted by the JSON specification, but not encouraged. Many libraries will ignore duplicate key-value pairs (typically keeping the last pair) when unmarshaling, but users should attempt to avoid adding duplicate keys.

func Pretty

func Pretty(json []byte) []byte

Pretty converts the input json into a more human readable format where each element is on it's own line with clear indentation.

func PrettyOptions

func PrettyOptions(json []byte, opts *Options) []byte

PrettyOptions is like Pretty but with customized options.

func SupportPrivateFields

func SupportPrivateFields()

func Ugly

func Ugly(json []byte) []byte

Ugly removes insignificant space characters from the input json byte slice and returns the compacted result.

func UglyInPlace

func UglyInPlace(json []byte) []byte

UglyInPlace removes insignificant space characters from the input json byte slice and returns the compacted result. This method reuses the input json buffer to avoid allocations. Do not use the original bytes slice upon return.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

type JSON

type JSON json.RawMessage

func (JSON) GormDataType

func (JSON) GormDataType() string

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

实现 driver.Valuer 接口,Value 返回 json value

type Number

type Number = json.Number

type Options

type Options struct {
	// Width is an max column width for single line arrays
	// Default is 80
	Width int
	// Prefix is a prefix for all lines
	// Default is an empty string
	Prefix string
	// Indent is the nested indentation
	// Default is two spaces
	Indent string
	// SortKeys will sort the keys alphabetically
	// Default is false
	SortKeys bool
}

Options is Pretty options

type Style

type Style struct {
	Key, String, Number [2]string
	True, False, Null   [2]string
	Append              func(dst []byte, c byte) []byte
}

Style is the color style

var TerminalStyle *Style

TerminalStyle is for terminals

Directories

Path Synopsis
Package gjson provides searching for json strings.
Package gjson provides searching for json strings.

Jump to

Keyboard shortcuts

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