jsonutil

package
v0.63.8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 14 Imported by: 62

Documentation

Index

Constants

View Source
const FileExt = ".json"

Variables

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

Functions

func Equal added in v0.50.0

func Equal(x, y io.Reader) (bool, error)

func EqualBytes added in v0.50.0

func EqualBytes(x, y []byte) (bool, error)

func EqualFiles added in v0.50.0

func EqualFiles(x, y string) (bool, error)

func IndentBytes added in v0.41.5

func IndentBytes(data []byte, prefix, indent string) ([]byte, error)

IndentBytes converts a JSON byte array into a prettified byte array.

func IndentReader added in v0.41.6

func IndentReader(r io.Reader, prefix, indent string) ([]byte, error)

IndentReader returns a byte slice of indented JSON given an `io.Reader`. It is useful to use with `http.Response.Body` which is an `io.ReadCloser`.

func MarshalBase64

func MarshalBase64(v any) (string, error)

func MarshalSimple

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

func MustMarshal

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

func MustMarshalIndent

func MustMarshalIndent(v any, prefix, indent string, embedError bool) []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 PrintReaderIndent added in v0.41.5

func PrintReaderIndent(r io.Reader, prefix, indent string) ([]byte, error)

PrintReaderIndent returns an indented JSON byte array given an `io.Reader`.

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) ([]byte, error)

func UnmarshalKeys added in v0.63.2

func UnmarshalKeys(b []byte) ([]string, error)

func UnmarshalKeysFile added in v0.63.2

func UnmarshalKeysFile(filename string) ([]string, 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 WriteFile

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

func WriteFileIndentBytes added in v0.63.6

func WriteFileIndentBytes(name string, data []byte, prefix, indent string, perm fs.FileMode) error

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

Jump to

Keyboard shortcuts

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