jsonutils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 21 Imported by: 75

README

jsonutils

Golang package to interact with JSON.

Documentation

Index

Constants

View Source
const (
	ErrJsonDictFailInsert = errors.Error("fail to insert object")

	ErrInvalidJsonDict    = errors.Error("not a valid JSONDict")
	ErrInvalidJsonArray   = errors.Error("not a valid JSONArray")
	ErrInvalidJsonInt     = errors.Error("not a valid number")
	ErrInvalidJsonFloat   = errors.Error("not a valid float")
	ErrInvalidJsonBoolean = errors.Error("not a valid boolean")
	ErrInvalidJsonString  = errors.Error("not a valid string")

	ErrJsonDictKeyNotFound = errors.Error("key not found")

	ErrUnsupported     = errors.Error("unsupported operation")
	ErrOutOfKeyRange   = errors.Error("out of key range")
	ErrOutOfIndexRange = errors.Error("out of index range")

	ErrInvalidChar = errors.Error("invalid char")
	ErrInvalidHex  = errors.Error("invalid hex")
	ErrInvalidRune = errors.Error("invalid 4 byte rune")

	ErrTypeMismatch         = errors.Error("unmarshal type mismatch")
	ErrArrayLengthMismatch  = errors.Error("unmarshal array length mismatch")
	ErrInterfaceUnsupported = errors.Error("do not known how to deserialize json into this interface type")
	ErrMapKeyMustString     = errors.Error("map key must be string")

	ErrMissingInputField = errors.Error("missing input field")
	ErrNilInputField     = errors.Error("nil input field")

	ErrYamlMissingDictKey = errors.Error("Cannot find JSONDict key")
	ErrYamlIllFormat      = errors.Error("Illformat")
)
View Source
const (
	TAG_DEPRECATED_BY = reflectutils.TAG_DEPRECATED_BY
)

Variables

View Source
var (
	JSONNull  = &JSONValue{}
	JSONTrue  = &JSONBool{data: true}
	JSONFalse = &JSONBool{data: false}
)
View Source
var (
	JSONDictType      reflect.Type
	JSONArrayType     reflect.Type
	JSONStringType    reflect.Type
	JSONIntType       reflect.Type
	JSONFloatType     reflect.Type
	JSONBoolType      reflect.Type
	JSONDictPtrType   reflect.Type
	JSONArrayPtrType  reflect.Type
	JSONStringPtrType reflect.Type
	JSONIntPtrType    reflect.Type
	JSONFloatPtrType  reflect.Type
	JSONBoolPtrType   reflect.Type
	JSONObjectType    reflect.Type
)

Functions

func CheckRequiredFields

func CheckRequiredFields(data JSONObject, fields []string) error

func GetAnyString

func GetAnyString(json JSONObject, keys []string) string

func GetAnyString2

func GetAnyString2(json JSONObject, keys []string) (string, string)

func GetQueryStringArray

func GetQueryStringArray(query JSONObject, key string) []string

func GetStringArray

func GetStringArray(o JSONObject, key ...string) ([]string, error)

func IsImplementStdMarshaler

func IsImplementStdMarshaler(v reflect.Value) json.Marshaler

func IsImplementStdUnmarshaler

func IsImplementStdUnmarshaler(v reflect.Value) json.Unmarshaler

func JSONArray2StringArray

func JSONArray2StringArray(arr []JSONObject) []string

func JSONDeserialize

func JSONDeserialize(objType reflect.Type, strVal string) (gotypes.ISerializable, error)

func QueryBoolean

func QueryBoolean(query JSONObject, key string, defVal bool) bool

func Update

func Update(dst, src interface{}) error

Types

type JSONArray

type JSONArray struct {
	JSONValue
	// contains filtered or unexported fields
}

func NewArray

func NewArray(objs ...JSONObject) *JSONArray

func NewStringArray

func NewStringArray(arr []string) *JSONArray

func (*JSONArray) Add

func (this *JSONArray) Add(objs ...JSONObject)

func (*JSONArray) Copy

func (this *JSONArray) Copy() *JSONArray

func (*JSONArray) DeepCopy

func (this *JSONArray) DeepCopy() interface{}

func (*JSONArray) Equals

func (arr *JSONArray) Equals(json JSONObject) bool

func (*JSONArray) GetArray

func (this *JSONArray) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONArray) GetAt

func (this *JSONArray) GetAt(i int, keys ...string) (JSONObject, error)

func (*JSONArray) GetString

func (this *JSONArray) GetString(keys ...string) (string, error)

func (*JSONArray) GetStringArray

func (this *JSONArray) GetStringArray() []string

func (*JSONArray) Interface

func (self *JSONArray) Interface() interface{}

func (*JSONArray) IsZero

func (this *JSONArray) IsZero() bool

func (*JSONArray) Length

func (this *JSONArray) Length() int

func (*JSONArray) PrettyString

func (this *JSONArray) PrettyString() string

func (*JSONArray) SetAt

func (this *JSONArray) SetAt(idx int, obj JSONObject)

func (*JSONArray) Size

func (this *JSONArray) Size() int

func (*JSONArray) String

func (this *JSONArray) String() string

func (*JSONArray) Unmarshal

func (this *JSONArray) Unmarshal(obj interface{}, keys ...string) error

func (*JSONArray) Value

func (this *JSONArray) Value() []JSONObject

Deprecated

func (*JSONArray) YAMLString

func (this *JSONArray) YAMLString() string

type JSONBool

type JSONBool struct {
	JSONValue
	// contains filtered or unexported fields
}

func NewBool

func NewBool(val bool) *JSONBool

func (*JSONBool) Bool

func (this *JSONBool) Bool(keys ...string) (bool, error)

func (*JSONBool) DeepCopy

func (this *JSONBool) DeepCopy() interface{}

func (*JSONBool) Equals

func (o *JSONBool) Equals(json JSONObject) bool

func (*JSONBool) GetArray

func (this *JSONBool) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONBool) GetString

func (this *JSONBool) GetString(keys ...string) (string, error)

func (*JSONBool) Interface

func (self *JSONBool) Interface() interface{}

func (*JSONBool) IsZero

func (this *JSONBool) IsZero() bool

func (*JSONBool) PrettyString

func (this *JSONBool) PrettyString() string

func (*JSONBool) String

func (this *JSONBool) String() string

func (*JSONBool) Value

func (this *JSONBool) Value() bool

Deprecated

func (*JSONBool) YAMLString

func (this *JSONBool) YAMLString() string

type JSONDict

type JSONDict struct {
	JSONValue
	// contains filtered or unexported fields
}

func Diff

func Diff(a, b *JSONDict) (aNoB, aDiffB, aAndB, bNoA *JSONDict)

func NewDict

func NewDict(objs ...JSONPair) *JSONDict

func (*JSONDict) Add

func (this *JSONDict) Add(o JSONObject, keys ...string) error

func (*JSONDict) Bool

func (this *JSONDict) Bool(keys ...string) (bool, error)

func (*JSONDict) Contains

func (this *JSONDict) Contains(keys ...string) bool

func (*JSONDict) ContainsIgnoreCases

func (this *JSONDict) ContainsIgnoreCases(keys ...string) bool

func (*JSONDict) Copy

func (this *JSONDict) Copy(excludes ...string) *JSONDict

func (*JSONDict) CopyExcludes

func (this *JSONDict) CopyExcludes(excludes ...string) *JSONDict

func (*JSONDict) CopyIncludes

func (this *JSONDict) CopyIncludes(includes ...string) *JSONDict

func (*JSONDict) DeepCopy

func (this *JSONDict) DeepCopy() interface{}

func (*JSONDict) Equals

func (dict *JSONDict) Equals(json JSONObject) bool

func (*JSONDict) Float

func (this *JSONDict) Float(keys ...string) (float64, error)

func (*JSONDict) Get

func (this *JSONDict) Get(keys ...string) (JSONObject, error)

func (*JSONDict) GetArray

func (this *JSONDict) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONDict) GetAt

func (this *JSONDict) GetAt(i int, keys ...string) (JSONObject, error)

func (*JSONDict) GetIgnoreCases

func (this *JSONDict) GetIgnoreCases(keys ...string) (JSONObject, error)

func (*JSONDict) GetMap

func (this *JSONDict) GetMap(keys ...string) (map[string]JSONObject, error)

func (*JSONDict) GetString

func (this *JSONDict) GetString(keys ...string) (string, error)

func (*JSONDict) GetTime

func (this *JSONDict) GetTime(keys ...string) (time.Time, error)

func (*JSONDict) Int

func (this *JSONDict) Int(keys ...string) (int64, error)

func (*JSONDict) Interface

func (self *JSONDict) Interface() interface{}

func (*JSONDict) IsZero

func (this *JSONDict) IsZero() bool

func (*JSONDict) Length

func (this *JSONDict) Length() int

func (*JSONDict) PrettyString

func (this *JSONDict) PrettyString() string

func (*JSONDict) QueryString

func (this *JSONDict) QueryString() string

func (*JSONDict) Remove

func (this *JSONDict) Remove(key string) bool

func (*JSONDict) RemoveIgnoreCase

func (this *JSONDict) RemoveIgnoreCase(key string) bool

func (*JSONDict) Set

func (this *JSONDict) Set(key string, value JSONObject)

func (*JSONDict) Size

func (this *JSONDict) Size() int

func (*JSONDict) SortedKeys

func (this *JSONDict) SortedKeys() []string

func (*JSONDict) String

func (this *JSONDict) String() string

func (*JSONDict) Unmarshal

func (this *JSONDict) Unmarshal(obj interface{}, keys ...string) error

func (*JSONDict) Update

func (dict *JSONDict) Update(json JSONObject)

func (*JSONDict) UpdateDefault

func (dict *JSONDict) UpdateDefault(json JSONObject)

func (*JSONDict) Value

func (this *JSONDict) Value() map[string]JSONObject

Deprecated

func (*JSONDict) YAMLString

func (this *JSONDict) YAMLString() string

type JSONError

type JSONError struct {
	// contains filtered or unexported fields
}

func NewJSONError

func NewJSONError(str []byte, pos int, msg string) *JSONError

func (*JSONError) Error

func (e *JSONError) Error() string

type JSONFloat

type JSONFloat struct {
	JSONValue
	// contains filtered or unexported fields
}

func NewFloat

func NewFloat(val float64) *JSONFloat

deprecated

func NewFloat32

func NewFloat32(val float32) *JSONFloat

func NewFloat64

func NewFloat64(val float64) *JSONFloat

func (*JSONFloat) DeepCopy

func (this *JSONFloat) DeepCopy() interface{}

func (*JSONFloat) Equals

func (o *JSONFloat) Equals(json JSONObject) bool

func (*JSONFloat) Float

func (this *JSONFloat) Float(keys ...string) (float64, error)

func (*JSONFloat) GetArray

func (this *JSONFloat) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONFloat) GetString

func (this *JSONFloat) GetString(keys ...string) (string, error)

func (*JSONFloat) Interface

func (self *JSONFloat) Interface() interface{}

func (*JSONFloat) IsZero

func (this *JSONFloat) IsZero() bool

func (*JSONFloat) PrettyString

func (this *JSONFloat) PrettyString() string

func (*JSONFloat) String

func (this *JSONFloat) String() string

func (*JSONFloat) Value

func (this *JSONFloat) Value() float64

Deprecated

func (*JSONFloat) YAMLString

func (this *JSONFloat) YAMLString() string

type JSONInt

type JSONInt struct {
	JSONValue
	// contains filtered or unexported fields
}

func NewInt

func NewInt(val int64) *JSONInt

func (*JSONInt) DeepCopy

func (this *JSONInt) DeepCopy() interface{}

func (*JSONInt) Equals

func (o *JSONInt) Equals(json JSONObject) bool

func (*JSONInt) Float

func (this *JSONInt) Float(keys ...string) (float64, error)

func (*JSONInt) GetArray

func (this *JSONInt) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONInt) GetString

func (this *JSONInt) GetString(keys ...string) (string, error)

func (*JSONInt) Int

func (this *JSONInt) Int(keys ...string) (int64, error)

func (*JSONInt) Interface

func (self *JSONInt) Interface() interface{}

func (*JSONInt) IsZero

func (this *JSONInt) IsZero() bool

func (*JSONInt) PrettyString

func (this *JSONInt) PrettyString() string

func (*JSONInt) String

func (this *JSONInt) String() string

func (*JSONInt) Value

func (this *JSONInt) Value() int64

Deprecated

func (*JSONInt) YAMLString

func (this *JSONInt) YAMLString() string

type JSONObject

type JSONObject interface {
	gotypes.ISerializable

	// String() string
	PrettyString() string

	YAMLString() string
	QueryString() string

	Contains(keys ...string) bool
	ContainsIgnoreCases(keys ...string) bool
	Get(keys ...string) (JSONObject, error)
	GetIgnoreCases(keys ...string) (JSONObject, error)
	GetAt(i int, keys ...string) (JSONObject, error)
	Int(keys ...string) (int64, error)
	Float(keys ...string) (float64, error)
	Bool(keys ...string) (bool, error)
	GetMap(keys ...string) (map[string]JSONObject, error)
	GetArray(keys ...string) ([]JSONObject, error)
	GetTime(keys ...string) (time.Time, error)
	GetString(keys ...string) (string, error)
	Unmarshal(obj interface{}, keys ...string) error
	Equals(obj JSONObject) bool

	// IsZero() bool
	Interface() interface{}
	// contains filtered or unexported methods
}

func DeepCopy

func DeepCopy(obj JSONObject) JSONObject

func GetArrayOfPrefix

func GetArrayOfPrefix(json JSONObject, prefix string) []JSONObject

func Marshal

func Marshal(obj interface{}) JSONObject

func MarshalAll

func MarshalAll(obj interface{}) JSONObject

func Parse

func Parse(str []byte) (JSONObject, error)

func ParseQueryString

func ParseQueryString(str string) (JSONObject, error)

func ParseString

func ParseString(str string) (JSONObject, error)

func ParseYAML

func ParseYAML(str string) (JSONObject, error)

type JSONPair

type JSONPair struct {
	// contains filtered or unexported fields
}

type JSONString

type JSONString struct {
	JSONValue
	// contains filtered or unexported fields
}

func NewString

func NewString(val string) *JSONString

func NewTimeString

func NewTimeString(tm time.Time) *JSONString

func (*JSONString) Bool

func (this *JSONString) Bool(keys ...string) (bool, error)

func (*JSONString) DeepCopy

func (this *JSONString) DeepCopy() interface{}

func (*JSONString) Equals

func (o *JSONString) Equals(json JSONObject) bool

func (*JSONString) Float

func (this *JSONString) Float(keys ...string) (float64, error)

func (*JSONString) GetArray

func (this *JSONString) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONString) GetString

func (this *JSONString) GetString(keys ...string) (string, error)

func (*JSONString) GetTime

func (this *JSONString) GetTime(keys ...string) (time.Time, error)

func (*JSONString) Int

func (this *JSONString) Int(keys ...string) (int64, error)

func (*JSONString) Interface

func (self *JSONString) Interface() interface{}

func (*JSONString) IsZero

func (this *JSONString) IsZero() bool

func (*JSONString) Length

func (this *JSONString) Length() int

func (*JSONString) PrettyString

func (this *JSONString) PrettyString() string

func (*JSONString) String

func (this *JSONString) String() string

func (*JSONString) Unmarshal

func (this *JSONString) Unmarshal(obj interface{}, keys ...string) error

func (*JSONString) Value

func (this *JSONString) Value() string

Deprecated

func (*JSONString) YAMLString

func (this *JSONString) YAMLString() string

type JSONValue

type JSONValue struct {
}

func (*JSONValue) Bool

func (this *JSONValue) Bool(keys ...string) (bool, error)

func (*JSONValue) Contains

func (this *JSONValue) Contains(keys ...string) bool

func (*JSONValue) ContainsIgnoreCases

func (this *JSONValue) ContainsIgnoreCases(keys ...string) bool

func (*JSONValue) Equals

func (o *JSONValue) Equals(json JSONObject) bool

func (*JSONValue) Float

func (this *JSONValue) Float(keys ...string) (float64, error)

func (*JSONValue) Get

func (this *JSONValue) Get(keys ...string) (JSONObject, error)

func (*JSONValue) GetArray

func (this *JSONValue) GetArray(keys ...string) ([]JSONObject, error)

func (*JSONValue) GetAt

func (this *JSONValue) GetAt(i int, keys ...string) (JSONObject, error)

func (*JSONValue) GetIgnoreCases

func (this *JSONValue) GetIgnoreCases(keys ...string) (JSONObject, error)

func (*JSONValue) GetMap

func (this *JSONValue) GetMap(keys ...string) (map[string]JSONObject, error)

func (*JSONValue) GetString

func (this *JSONValue) GetString(keys ...string) (string, error)

func (*JSONValue) GetTime

func (this *JSONValue) GetTime(keys ...string) (time.Time, error)

func (*JSONValue) Int

func (this *JSONValue) Int(keys ...string) (int64, error)

func (*JSONValue) Interface

func (self *JSONValue) Interface() interface{}

func (*JSONValue) IsZero

func (this *JSONValue) IsZero() bool

func (*JSONValue) PrettyString

func (this *JSONValue) PrettyString() string

func (*JSONValue) QueryString

func (this *JSONValue) QueryString() string

func (*JSONValue) String

func (this *JSONValue) String() string

func (*JSONValue) Unmarshal

func (this *JSONValue) Unmarshal(obj interface{}, keys ...string) error

func (*JSONValue) YAMLString

func (this *JSONValue) YAMLString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL