jsonutil

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package jsonutil 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 interface{}, 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 MustIndent

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

MustIndent behaves like Indent but will panic on errors.

func MustMarshal

func MustMarshal(v interface{}) []byte

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

func MustMarshalIndent

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

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

func MustUnmarshal

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

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

Types

type Timestamp added in v1.2.0

type Timestamp struct{ time.Time }

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

func (Timestamp) MarshalJSON added in v1.2.0

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

Marshal in to JSON.

func (*Timestamp) UnmarshalJSON added in v1.2.0

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