Documentation ¶
Index ¶
- func AsJSONObject(b []byte) map[string]*JSON
- func FromJSONArray(j []*JSON) []byte
- func FromJSONObject(j map[string]*JSON) []byte
- func Marshal(v any) ([]byte, error)
- func MarshalWrite(w io.Writer, v any) error
- func Unmarshal(data []byte, v any) error
- func UnmarshalRead(r io.Reader, v any) error
- type Any
- func (a *Any) Array() []*Any
- func (a *Any) Field(name string) *Any
- func (a *Any) Float() float64
- func (a *Any) Format(state fmt.State, verb rune)
- func (a *Any) Int() int64
- func (a *Any) IsArray() bool
- func (a *Any) IsEmpty() bool
- func (a *Any) IsNull() bool
- func (a *Any) IsObject() bool
- func (a *Any) IterElems(fn func(int, *Any))
- func (a *Any) IterFields(fn func(string, *Any))
- func (a *Any) MarshalJSON() ([]byte, error)
- func (a *Any) Object() map[string]*Any
- func (a *Any) SetArray(arr []*Any)
- func (a *Any) SetFloat(f float64)
- func (a *Any) SetInt(i int64)
- func (a *Any) SetNull()
- func (a *Any) SetObject(obj map[string]*Any)
- func (a *Any) SetString(s string)
- func (a *Any) SetUint(u uint64)
- func (a *Any) String() string
- func (a *Any) Type() interface{}
- func (a *Any) Uint() uint64
- func (a *Any) UnmarshalJSON(data []byte) error
- type JSON
- func (j *JSON) Any() (a *Any, err error)
- func (j *JSON) Arr() []*JSON
- func (j *JSON) Array() (arr []*JSON, err error)
- func (j *JSON) Bool() (b bool, err error)
- func (j *JSON) Float() (f float64, err error)
- func (j *JSON) Int() (i int64, err error)
- func (j *JSON) IsArray() bool
- func (j *JSON) IsEmpty() bool
- func (j *JSON) IsNull() bool
- func (j *JSON) IsObject() bool
- func (j *JSON) MarshalJSON() ([]byte, error)
- func (j *JSON) Obj() map[string]*JSON
- func (j *JSON) Object() (obj map[string]*JSON, err error)
- func (j *JSON) SetAny(a *Any)
- func (j *JSON) SetArray(arr []*JSON)
- func (j *JSON) SetBool(b bool)
- func (j *JSON) SetFloat(f float64)
- func (j *JSON) SetFloatLossy(f float64)
- func (j *JSON) SetInt(i int64)
- func (j *JSON) SetNull()
- func (j *JSON) SetObject(obj map[string]*JSON)
- func (j *JSON) SetString(s string)
- func (j *JSON) SetStringHTMLEscaped(s string)
- func (j *JSON) SetUint(u uint64)
- func (j *JSON) SetValue(v any) (err error)
- func (j *JSON) String() (s string, err error)
- func (j *JSON) Uint() (u uint64, err error)
- func (j *JSON) UnmarshalJSON(data []byte) error
- func (j *JSON) Value(v any) (err error)
- func (j *JSON) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsJSONObject ¶
Useful conversion methods for byte slices to / from map[string]*JSON.
func FromJSONArray ¶
Useful conversion methods for byte slices to / from []*JSON.
func FromJSONObject ¶
Useful conversion methods for byte slices to / from map[string]*JSON.
func Marshal ¶
Marshal: see github.com/json-iterator/go.Marshal() (using the default configuration).
func MarshalWrite ¶
MarshalWrite is a streamed alternative to Marshal().
Types ¶
type Any ¶
type Any struct {
// contains filtered or unexported fields
}
Any represents a generic json value.
func (*Any) IterElems ¶
IterElems iterates the elements of Any{} cast as an array, successfuly casted as-so, or handling as a single element.
func (*Any) IterFields ¶
IterFields iterates the fields of Any{} cast as an object.
func (*Any) MarshalJSON ¶
MarshalJSON formats Any{} as json data.
func (*Any) Type ¶
func (a *Any) Type() interface{}
Type returns the underlying Any{} interface value.
func (*Any) UnmarshalJSON ¶
UnmarshalJSON parses the given json data into Any{}.
type JSON ¶
type JSON struct{ B []byte }
JSON represents unparsed json data, the helper methods allow you to lazily parse the data *as* you need it.
func AsJSONArray ¶
Useful conversion methods for byte slices to / from []*JSON.
func (*JSON) IsArray ¶
IsArray returns whether JSON{} is a possible array (i.e. has surrounding square braces).
func (*JSON) IsObject ¶
IsObject returns whether JSON{} is a possible object (i.e. has surrounding curl braces).
func (*JSON) MarshalJSON ¶
MarshalJSON directly returns the data stored in JSON{}, or the json "null" value if nil.
func (*JSON) SetFloatLossy ¶
SetFloatLossy sets the data in JSON{} to marshaled float64 bytes (much faster, though with only 6 digits precision).
func (*JSON) SetNull ¶
func (j *JSON) SetNull()
SetNull sets the JSON{} data to the json "null" value.
func (*JSON) SetStringHTMLEscaped ¶
SetString sets the data in JSON{} to marshaled string bytes (with HTML special chars escaped).
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON copies the data into JSON{}, delaying actual unmarshaling.