json

package
Version: v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: GPL-3.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyJSONList = List("[]")
View Source
var EmptyJSONObject = Object("{}")

Functions

func NewJsonDecoder

func NewJsonDecoder() *jsonDecoder

func ParseBody

func ParseBody(r *http.Request, model interface{}) error

Types

type List

type List json.RawMessage

JSONText is a json.RawMessage, which is a []byte underneath. Value() validates the json format in the source, and returns an error if the json is not valid. Scan does no validation. JSONText additionally implements `Unmarshal`, which unmarshals the json within to an interface{}

func FromList

func FromList(l []string) (List, error)

func FromListOrEmpty

func FromListOrEmpty(l []string) List

func StructToJsonList

func StructToJsonList(v interface{}) (List, error)

func StructToJsonListOrEmpty

func StructToJsonListOrEmpty(v interface{}) List

func (*List) AsList

func (j *List) AsList() ([]string, error)

func (*List) AsListOrEmpty

func (j *List) AsListOrEmpty() []string

func (List) MarshalJSON

func (j List) MarshalJSON() ([]byte, error)

MarshalJSON returns the *j as the JSON encoding of j.

func (*List) Scan

func (j *List) Scan(src interface{}) error

Scan stores the src in *j. No validation is done.

func (List) String

func (j List) String() string

String supports pretty printing for JSONText types.

func (*List) Unmarshal

func (j *List) Unmarshal(v interface{}) error

Unmarshal unmarshal's the json in j to v, as in json.Unmarshal.

func (*List) UnmarshalJSON

func (j *List) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *j to a copy of Repo

func (List) Value

func (j List) Value() (driver.Value, error)

Value returns j as a value. This does a validating unmarshal into another RawMessage. If j is invalid json, it returns an error.

type Object

type Object json.RawMessage

JSONText is a json.RawMessage, which is a []byte underneath. Value() validates the json format in the source, and returns an error if the json is not valid. Scan does no validation. JSONText additionally implements `Unmarshal`, which unmarshals the json within to an interface{}

func FromMap

func FromMap(m map[string]interface{}) (Object, error)

func FromMapOrEmpty

func FromMapOrEmpty(m map[string]interface{}) Object

func FromStringMap

func FromStringMap(m map[string]string) (Object, error)

func FromStringMapOrEmpty

func FromStringMapOrEmpty(m map[string]string) Object

func StructToJsonObject

func StructToJsonObject(v interface{}) (Object, error)

func StructToJsonObjectOrEmpty

func StructToJsonObjectOrEmpty(v interface{}) Object

func (*Object) AsMap

func (j *Object) AsMap() (map[string]interface{}, error)

func (*Object) AsMapOrEmpty

func (j *Object) AsMapOrEmpty() map[string]interface{}

AsMapOrEmpty returns a map or if it can't unmarshal it, it returns an empty map

func (*Object) AsStringMap

func (j *Object) AsStringMap() (map[string]string, error)

func (*Object) AsStringMapOrEmpty

func (j *Object) AsStringMapOrEmpty() map[string]string

func (Object) MarshalJSON

func (j Object) MarshalJSON() ([]byte, error)

MarshalJSON returns the *j as the JSON encoding of j.

func (*Object) Scan

func (j *Object) Scan(src interface{}) error

Scan stores the src in *j. No validation is done.

func (Object) String

func (j Object) String() string

String supports pretty printing for JSONText types.

func (*Object) Unmarshal

func (j *Object) Unmarshal(v interface{}) error

Unmarshal unmarshal's the json in j to v, as in json.Unmarshal.

func (*Object) UnmarshalJSON

func (j *Object) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *j to a copy of Repo

func (Object) Value

func (j Object) Value() (driver.Value, error)

Value returns j as a value. This does a validating unmarshal into another RawMessage. If j is invalid json, it returns an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL