jsonutil

package
v0.68.10 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 14 Imported by: 63

Documentation

Index

Constants

View Source
const (
	EmptyArray  = "[]"
	EmptyObject = "{}"
	FileExt     = ".json"
)

Variables

View Source
var (
	MarshalPrefix = ""
	MarshalIndent = "    "
)

Functions

func MarshalBase64

func MarshalBase64(v any) (string, error)

func MarshalFile added in v0.66.4

func MarshalFile(filename string, v any, prefix, indent string, perm fs.FileMode) error

func MarshalOrDefault added in v0.64.9

func MarshalOrDefault(v any, def []byte) ([]byte, error)

MarshalOrDefault returns the supplied default value in the event of an error. It also returns the error for processing.

func MarshalSimple

func MarshalSimple(v any, prefix, indent string) ([]byte, error)

func MarshalSlice added in v0.67.5

func MarshalSlice(v ...any) ([]byte, error)

MarshalSlice marshals any slice, using `fmt.Sprintf()` for non-strings.

func MustMarshal

func MustMarshal(v any, embedError bool) []byte

func MustMarshalIndent

func MustMarshalIndent(v any, prefix, indent string, embedError bool) []byte

func MustMarshalOrDefault added in v0.64.9

func MustMarshalOrDefault(v any, def []byte) []byte

func MustMarshalSimple

func MustMarshalSimple(v any, prefix, indent string) []byte

func MustMarshalString

func MustMarshalString(v any, embedError bool) string

func MustUnmarshal added in v0.37.5

func MustUnmarshal(b []byte, v any)

func SHA512d256Base32 added in v0.66.6

func SHA512d256Base32(v any, padding rune) (string, error)

func UnmarshalAny added in v0.60.0

func UnmarshalAny(data, v any) error

UnmarshalAny will unmarshal anything to `v`, including first marshalling anything that is not a byte array to a JSON byte array.

func UnmarshalFile added in v0.63.2

func UnmarshalFile(filename string, v any) error

func UnmarshalFileWithBytes added in v0.66.4

func UnmarshalFileWithBytes(filename string, v any) ([]byte, error)

func UnmarshalMSI

func UnmarshalMSI(data map[string]any, v any) error

func UnmarshalReader

func UnmarshalReader(r io.Reader, v any) ([]byte, error)

func UnmarshalStrict added in v0.39.4

func UnmarshalStrict(b []byte, v any) error

UnmarshalStrict returns an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.

func UnmarshalWithLoc added in v0.67.2

func UnmarshalWithLoc(data []byte, v any) error

func ValidateQuick added in v0.68.0

func ValidateQuick(b []byte, fuzzy bool) bool

ValidateQuick checks to see if the first and last bytes match `{}[]`. Set `fuzzy` to true to trim spaces from the beginning and end. It is not Design to provide full validation but quick decision making on whether to attempt JSON parsing.

Types

type Bool

type Bool bool

Bool implements a tolerant reader for `bool` type.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

type Int64

type Int64 int64

Int64 implements a tolerant reader for `int64` type.

func (*Int64) UnmarshalJSON

func (i64 *Int64) UnmarshalJSON(data []byte) error

type String added in v0.48.0

type String string

String implements a tolerant reader for `string` type, including flexible input conversion to strings from numbers and integers.

func (*String) UnmarshalJSON added in v0.48.0

func (s *String) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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