zjson

package
v0.0.0-...-d785515 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Overview

Package zjson provides functions for working with JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Indent

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

Indent a json string by unmarshalling it and marshalling it with MarshalIndent.

The data will be unmarshalled in to v, which must be a pointer. Example:

Indent(`{"a": "b"}`, &map[string]string{}, "", "  ")

func IndentString

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

IndentString is like Indent, but returns a string.

func MustIndent

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

MustIndent behaves like Indent but will panic on errors.

func MustIndentString

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

MustIndentString is like MustIndent, but returns a string.

func MustMarshal

func MustMarshal(v any) []byte

MustMarshal behaves like json.Marshal but will panic on errors.

func MustMarshalIndent

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

MustMarshalIndent behaves like json.MarshalIndent but will panic on errors.

func MustMarshalIndentString

func MustMarshalIndentString(v any, prefix, indent string) string

MustMarshalIndentString is like MustMarshalIndent, but returns a string.

func MustMarshalString

func MustMarshalString(v any) string

MustMarshalString is like MustMarshal, but returns a string.

func MustUnmarshal

func MustUnmarshal(data []byte, v any)

MustUnmarshal behaves like json.Unmarshal but will panic on errors.

func MustUnmarshalTo

func MustUnmarshalTo(data []byte, target reflect.Type) any

MustUnmarshalTo behaves like UnmarshalTo but will panic on errors.

func UnmarshalTo

func UnmarshalTo(data []byte, target reflect.Type) (any, error)

UnmarshalTo unmarshals the JSON in data to a new instance of target.

Target can be any type that json.Unmarshal can unmarshal to, and doesn't need to be a pointer. The returned value is always a pointer.

Types

type Int

type Int int64

Int for APIs that return numbers as strings.

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

Marshal in to JSON.

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(v []byte) error

Unmarshal a string timestamp as an int.

type Timestamp

type Timestamp struct{ time.Time }

Timestamp for APIs that return dates as a numeric Unix timestamp.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

Marshal in to JSON.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(v []byte) error

Unmarshal a Unix timestamp as a date.

Jump to

Keyboard shortcuts

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