Documentation
¶
Overview ¶
Package ojson provides several data types that can be used to encode and decode JSON while preserving object keys order. The name "ojson" stands for "Ordered JSON".
Index ¶
- type Any
- type Array
- type Object
- func (o *Object) Clear()
- func (o *Object) Delete(key string)
- func (o *Object) Get(key string) (v any, ok bool)
- func (o *Object) Len() int
- func (o *Object) MarshalJSON() ([]byte, error)
- func (o *Object) Range(f func(key string, value any) bool)
- func (o *Object) Set(key string, value any)
- func (o *Object) UnmarshalJSON(d []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Any ¶
type Any struct {
// contains filtered or unexported fields
}
Any represents any Go value. When using it to decode a JSON value it ensures that embedded JSON objects are decoded as Object.
func (Any) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Any) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Array ¶
type Array []any
Array represents a slice of any values. When using it to decode a JSON array it ensures that embedded JSON objects are decoded as Object.
func (*Array) UnmarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents a JSON object. It is the equivalent of map[string]any but when used to decode/encode a JSON object it preserves the object keys order. It can also be used as an ordered map.
func (*Object) Clear ¶
func (o *Object) Clear()
Clear deletes all entries in the object, resulting in an empty object.
func (*Object) Get ¶
Get returns the value stored in the object for a key, or nil if no value is present. The ok result indicates whether value was found in the object.
func (*Object) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Object) Range ¶
Range calls f sequentially for each key and value present in the object. If f returns false, range stops the iteration.
func (*Object) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.