jsonutil

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 13 Imported by: 62

Documentation

Index

Constants

View Source
const FileExt = ".json"

Variables

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

Functions

func GetSubobjectBytes

func GetSubobjectBytes(data []byte, key string) ([]byte, error)

func IndentBytes added in v0.41.5

func IndentBytes(b []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 JSONParserGetArrayIntOneOnly added in v0.37.0

func JSONParserGetArrayIntOneOnly(data []byte, key string) (int, error)

func JSONParserGetArrayString added in v0.37.0

func JSONParserGetArrayString(data []byte, key string) ([]string, error)

func JSONParserGetArrayStringOneOnly added in v0.37.0

func JSONParserGetArrayStringOneOnly(data []byte, key string) (string, error)

func MarshalBase64

func MarshalBase64(i interface{}) (string, error)

func MarshalSimple

func MarshalSimple(v interface{}, prefix, indent string) ([]byte, error)

func MustGetSubobjectBytes

func MustGetSubobjectBytes(data []byte, key string) []byte

func MustMarshal

func MustMarshal(i interface{}, embedError bool) []byte

func MustMarshalIndent

func MustMarshalIndent(i interface{}, prefix, indent string, embedError bool) []byte

func MustMarshalSimple

func MustMarshalSimple(v interface{}, prefix, indent string) []byte

func MustMarshalString

func MustMarshalString(i interface{}, embedError bool) string

func MustUnmarshal added in v0.37.5

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

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 ReadFile

func ReadFile(filename string, v interface{}) ([]byte, error)

func UnmarshalMSI

func UnmarshalMSI(data map[string]interface{}, v interface{}) error

func UnmarshalReader

func UnmarshalReader(r io.Reader, v interface{}) ([]byte, error)

func UnmarshalStrict added in v0.39.4

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

func WriteFile

func WriteFile(filename string, v interface{}, 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

func (*Bool) Value

func (b *Bool) Value() bool

type Int64

type Int64 int64

Int64 implements a tolerant reader for `int64` type.

func (*Int64) UnmarshalJSON

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

func (*Int64) Value

func (i64 *Int64) Value() int64

Jump to

Keyboard shortcuts

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