Documentation
¶
Index ¶
- Variables
- func AsArray(data []byte) ([]byte, error)
- func Coalesce(getter func(Map) (bool, error), docs ...Map) (bool, error)
- func CoalesceString(ctx context.Context, path string, defVal string, docs ...Map) (string, error)
- func Ensure(doc []byte) []byte
- func EnumProperties(object interface{}) (list []string, err error)
- func Get(doc []byte, getters ...func(Map) error) (err error)
- func GetProperty(ctx context.Context, object interface{}, key string) (interface{}, error)
- func GetPropertyEx(ctx context.Context, object interface{}, key string) (val interface{}, err error)
- func ImportProperties(ctx context.Context, object interface{}, getter types.Getter) error
- func IsArray(data []byte) (bool, error)
- func IsEmpty(doc []byte) bool
- func IsEqual(a, b RawMessage) bool
- func IsObject(data []byte) (bool, error)
- func Marshal(value interface{}) ([]byte, error)
- func MarshalIndent(value interface{}) ([]byte, error)
- func Merge(docs ...[]byte) ([]byte, error)
- func RestoreString(ctx context.Context, path string, docs ...Map) error
- func SetProperty(ctx context.Context, object interface{}, key string, value interface{}) error
- func SetPropertyEx(ctx context.Context, object interface{}, key string, val interface{}) (err error)
- func TypeOf(in io.Reader) (string, error)
- func Unmarshal(raw []byte, value interface{}) error
- func Update(doc []byte, actions ...func(Map) error) ([]byte, error)
- func UpdateAll(doc []byte, actions ...func(Map) error) ([]byte, error)
- func WithAny(key string, ref *any) func(Map) error
- func WithBoolean(key string, ref *bool) func(Map) error
- func WithDefaultValue(key string, val interface{}) func(Map) error
- func WithDuration(key string, ref *time.Duration) func(Map) error
- func WithFloat(key string, ref *float64) func(Map) error
- func WithIf(cond bool, action func(Map) error) func(Map) error
- func WithInteger(key string, ref *int64) func(Map) error
- func WithJson(key string, ref *RawMessage) func(Map) error
- func WithRemove(key string) func(Map) error
- func WithString(key string, ref *string) func(Map) error
- func WithValue(key string, val interface{}) func(Map) error
- func WithValues(fields map[string]interface{}) func(Map) error
- type AtomGetter
- type AtomSetter
- type Boolean
- type Logical
- type Map
- func (that Map) Clone() Map
- func (that Map) Contains(name string) bool
- func (that Map) ExpandBy(right Map)
- func (that Map) GetBoolean(ctx context.Context, name string, defVal bool) (res bool, err error)
- func (that Map) GetDuration(ctx context.Context, name string, defVal time.Duration) (res time.Duration, err error)
- func (that Map) GetFloat(ctx context.Context, name string, defVal float64) (res float64, err error)
- func (that Map) GetInteger(ctx context.Context, name string, defVal int64) (res int64, err error)
- func (that Map) GetJson(ctx context.Context, name string, defVal RawMessage) (res RawMessage, err error)
- func (that Map) GetProperty(ctx context.Context, name string) (interface{}, error)
- func (that Map) GetString(ctx context.Context, name string, defVal string) (res string, err error)
- func (that Map) Hash() (string, error)
- func (that Map) Json() ([]byte, error)
- func (that Map) Marshal() ([]byte, error)
- func (that Map) MarshalIndent() ([]byte, error)
- func (that Map) NewScope(name string) Map
- func (that Map) SaveToFile(filename string) error
- func (that Map) Scope(name string) Map
- func (that Map) SetBoolean(ctx context.Context, name string, value bool) error
- func (that Map) SetDuration(ctx context.Context, name string, value time.Duration) error
- func (that Map) SetFloat(ctx context.Context, name string, value float64) error
- func (that Map) SetInteger(ctx context.Context, name string, value int64) error
- func (that Map) SetJson(ctx context.Context, name string, value RawMessage) error
- func (that Map) SetProperty(ctx context.Context, name string, value interface{}) error
- func (that Map) SetString(ctx context.Context, name string, value string) error
- func (that Map) String() string
- func (that Map) ToBoolean(ctx context.Context, name string, defVal bool) bool
- func (that Map) ToDuration(ctx context.Context, name string, defVal time.Duration) time.Duration
- func (that Map) ToFloat(ctx context.Context, name string, defVal float64) float64
- func (that Map) ToInteger(ctx context.Context, name string, defVal int64) int64
- func (that Map) ToJson(ctx context.Context, name string, defVal RawMessage) RawMessage
- func (that Map) ToMap(ctx context.Context, name string) Map
- func (that Map) ToMaps(ctx context.Context, name string) []Map
- func (that Map) ToSlice(ctx context.Context, name string) []interface{}
- func (that Map) ToString(ctx context.Context, name string, defVal string) string
- func (that Map) Unmarshal(data []byte) error
- type Number
- type RawMessage
- type String
- type Strings
Constants ¶
This section is empty.
Variables ¶
var Config = jsoniter.Config{ EscapeHTML: false, SortMapKeys: false, ValidateJsonRawMessage: false, UseNumber: true, }.Froze()
Config is a custom JSON configuration.
var ConfigSorted = jsoniter.Config{ EscapeHTML: false, SortMapKeys: true, ValidateJsonRawMessage: false, UseNumber: true, }.Froze()
ConfigSorted is a custom JSON configuration.
var Empty = RawMessage("{}")
Empty is empty document
Functions ¶
func CoalesceString ¶
CoalesceString is a helper function to coalesce a string from multiple documents.
func Ensure ¶
Ensure is a helper function to ensure a JSON document is not empty. It takes a document and returns an empty object if the document is empty.
func EnumProperties ¶
EnumProperties is a helper function to export properties from an object. It takes an object and returns a map of properties. Example: ExportProperties(ctx, object)
func Get ¶
Get is a helper function to extract a value from a JSON document. Example: Get(doc, GetInteger("key", 0))
func GetProperty ¶
GetProperty is a helper function to extract a value from an object. It takes an object and a key and returns the value. It can panic. Example: GetProperty(ctx, object, "key")
func GetPropertyEx ¶
func GetPropertyEx( ctx context.Context, object interface{}, key string, ) (val interface{}, err error)
GetPropertyEx is a helper function to extract a value from an object It is wrapper for JsonGetProperty with panic handling. Example: GetPropertyEx(ctx, object, "key")
func ImportProperties ¶
ImportProperties is a helper function to import properties into an object. It takes an object and a getter and sets the properties. Example: ImportProperties(ctx, object, getter)
func IsEqual ¶
func IsEqual(a, b RawMessage) bool
func MarshalIndent ¶
MarshalIndent is a helper function to marshal a JSON document with indentation.
func SetProperty ¶
SetProperty is a helper function to set a value in an object. It takes an object, a key and a value and sets the value. It can panic. Example: SetProperty(ctx, object, "key", "value")
func SetPropertyEx ¶
func SetPropertyEx( ctx context.Context, object interface{}, key string, val interface{}, ) (err error)
SetPropertyEx is a helper function to set a value in an object. It is wrapper for JsonSetProperty with panic handling. Example: SetPropertyEx(ctx, object, "key", "value")
func TypeOf ¶
TypeOf is a helper function to determine the type of a JSON document. It takes a document and returns the type (array, object). Example: TypeOf(doc)
func Update ¶
Update is a helper function to update a JSON document. It takes a document and a function that takes a Map and returns an error. Example: Update(doc, func(m Map) error { m["key"] = "value"; return nil })
func WithAny ¶
WihtAny is a helper function to extract a any value from a JSON document. See Get for more information.
func WithBoolean ¶
WithBoolean is a helper function to extract a boolean from a JSON document. See Get for more information.
func WithDefaultValue ¶
WithDefaultValue is a helper function to set a default value in a JSON document. See Update for more information.
func WithDuration ¶
WithDuration is a helper function to extract a time from a JSON document. See Get for more information.
func WithFloat ¶
WithFloat is a helper function to extract a float from a JSON document. See Get for more information.
func WithIf ¶
WithIf is a helper function to conditionally execute an action. See Update for more information.
func WithInteger ¶
WithInteger is a helper function to extract an integer from a JSON document. See Get for more information.
func WithJson ¶
func WithJson(key string, ref *RawMessage) func(Map) error
WithJson is a helper function to extract a raw message from a JSON document. See Get for more information.
func WithRemove ¶
WithRemove is a helper function to remove a value from a JSON document.
func WithString ¶
WithString is a helper function to extract a string from a JSON document. See Get for more information.
func WithValue ¶
WithValue is a helper function to override a value in a JSON document. See Update for more information.
func WithValues ¶
WithValues is a helper function to update a JSON document with a map of values. It takes a document and a map of fields to update. Example: Update(doc, Values(map[string]interface{}{"key": "value"}))
Types ¶
type AtomGetter ¶
type AtomSetter ¶
type Boolean ¶
type Boolean bool
Boolean is a custom type for JSON booleans.
func (*Boolean) MarshalJSON ¶
func (*Boolean) UnmarshalJSON ¶
type Logical ¶
type Logical int
Logical is a custom type for JSON.
func (*Logical) MarshalJSON ¶
func (*Logical) UnmarshalJSON ¶
type Map ¶
type Map map[string]interface{}
Map is standard map, that implements GetterSetter
func NewMapFromFile ¶
NewMapFromFile returns map, that loaded from file
func NewMapFromFiles ¶
NewMapFromFiles returns map as result join from files.
func NewMapFromNativeStruct ¶
func NewMapFromNativeStruct(val interface{}) Map
NewMapFromNativeStruct is constructor for creating Map from native struct.
func NewMapFromStruct ¶
NewMapFromStruct is constructor for creating Map from standard map.
func (Map) ExpandBy ¶
ExpandBy is routine, that allow expand map by additional values from another map (recursive).
func (Map) GetBoolean ¶
func (Map) GetDuration ¶
func (Map) GetInteger ¶
func (Map) GetJson ¶
func (that Map) GetJson( ctx context.Context, name string, defVal RawMessage, ) (res RawMessage, err error)
func (Map) GetProperty ¶
func (Map) MarshalIndent ¶
func (Map) SaveToFile ¶
func (Map) SetBoolean ¶
func (Map) SetDuration ¶
func (Map) SetInteger ¶
func (Map) SetProperty ¶
func (Map) ToDuration ¶
func (Map) ToJson ¶
func (that Map) ToJson( ctx context.Context, name string, defVal RawMessage, ) RawMessage
type RawMessage ¶
type RawMessage = json.RawMessage
func Extract ¶
func Extract( doc []byte, path string, ) (RawMessage, error)
Extract is a helper function to extract a value from a JSON document.
func Normalize ¶
func Normalize(data RawMessage) (RawMessage, error)
type String ¶
type String string
String is a custom type for JSON strings.
func (*String) MarshalJSON ¶
func (*String) UnmarshalJSON ¶
type Strings ¶
type Strings struct {
// contains filtered or unexported fields
}
Strings is a custom type for JSON strings.