jsons

package
v0.12.17 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Unmarshal     = json.Unmarshal
	Marshal       = json.Marshal
	MarshalIndent = json.MarshalIndent

	UnmarshalString = func(s string, val any) error { return Unmarshal(string2Bytes(s), val) }
	MarshalString   = func(val any) (string, error) {
		bs, err := Marshal(val)
		if err != nil {
			return "", err
		}
		return bytes2String(bs), nil
	}

	NewEncoder = func(w io.Writer) JSONEncoder {
		return json.NewEncoder(w)
	}
	NewDecoder = func(r io.Reader) JSONDecoder {
		return json.NewDecoder(r)
	}

	MustMarshal = func(v any) []byte {
		bs, err := Marshal(v)
		if err != nil {
			panic(err)
		}
		return bs
	}
	MustUnmarshal = func(bs []byte, v any) {
		err := Unmarshal(bs, v)
		if err != nil {
			panic(err)
		}
	}
	MustMarshalIndent = func(v any, prefix, indent string) []byte {
		bs, err := MarshalIndent(v, prefix, indent)
		if err != nil {
			panic(err)
		}
		return bs
	}
	MustMarshalString = func(v any) string {
		bs, err := Marshal(v)
		if err != nil {
			panic(err)
		}
		return bytes2String(bs)
	}
	MustUnmarshalString = func(s string, v any) {
		err := Unmarshal(string2Bytes(s), v)
		if err != nil {
			panic(err)
		}
	}
)

Functions

This section is empty.

Types

type JSONDecoder added in v0.10.0

type JSONDecoder interface {
	Decode(v any) error
	UseNumber()
	DisallowUnknownFields()
	Buffered() io.Reader
	More() bool
}

type JSONEncoder added in v0.10.0

type JSONEncoder interface {
	Encode(v any) error
	SetIndent(prefix, indent string)
	SetEscapeHTML(on bool)
}

Jump to

Keyboard shortcuts

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