Documentation ¶
Index ¶
- Constants
- func FillFromJsonObject(j Typ, pointerToStruct any) error
- func ValidateJPathSyntax(path string) error
- type StringAnyMap
- type Typ
- func EmptyNotNullJsonObject() Typ
- func NewJsonObject(key string, value interface{}) Typ
- func SetValueAndOverrideInJsonObjectByJPath(obj Typ, path string, valueToSet any, override bool) (Typ, error)
- func SetValueInJsonObjectByJPath(obj Typ, path string, valueToSet any) (Typ, error)
- func ToJsonObject(v interface{}) (Typ, error)
- func (j *Typ) AsByteSlice() []byte
- func (j *Typ) FindKeyByValue(value interface{}) string
- func (j *Typ) GetTopLevelElement(key string) any
- func (j *Typ) GetValueFromJsonObjectByJPath(path string) (string, any, appError.Typ)
- func (j *Typ) HasTopLevelArray() bool
- func (j *Typ) IsEmpty() bool
- func (j *Typ) IsNotEmpty() bool
- func (j Typ) MarshalJSON() ([]byte, error)
- func (j *Typ) PrettyString() string
- func (j *Typ) Scan(value interface{}) error
- func (j *Typ) SetNewTopLevelElement(key string, value interface{}) (replacedExistingKey bool)
- func (j *Typ) SetValueByJPath(path string, valueToSet any) error
- func (j *Typ) String() string
- func (j *Typ) StringOrBlankObject() string
- func (j *Typ) StringOrNil() *string
- func (j *Typ) UnmarshalJSON(dataToUnmarshal []byte) error
- func (j *Typ) Value() (driver.Value, error)
Constants ¶
const ( TypeAny = "any" TypeInt = "int" TypeInt64 = "int64" TypeFloat64 = "float64" TypeString = "string" TypeBool = "bool" TypeObject = "object" TypeNil = "nil" TypeArrayAny = "array/any" TypeArrayInt = "array/int" TypeArrayFloat64 = "array/float64" TypeArrayString = "array/string" TypeArrayBool = "array/bool" TypeArrayObject = "array/object" TypeUnknown = "unknown" )
IMPORTANT: THIS TYPE CANNOT HANDLE A TOP LEVEL JSON ARRAY (any valid JSON document starting with '[')
It can handle arrays nested in a JSON object though.
Variables ¶
This section is empty.
Functions ¶
func FillFromJsonObject ¶ added in v0.1.12
FillFromJsonObject will take a jsonObject Typ and fill the pointerToStruct with the value extracted from the jsonObject
func ValidateJPathSyntax ¶
ValidateJPathSyntax validates JPath syntax (not against any specific Typ)
Types ¶
type StringAnyMap ¶
type Typ ¶
type Typ struct { Valid bool StringAnyMap // contains filtered or unexported fields }
var NullJsonObject Typ
func EmptyNotNullJsonObject ¶
func EmptyNotNullJsonObject() Typ
EmptyNotNullJsonObject returns a new blank Typ NOTE: We cannot use a var for the EmptyNotNullJsonObject value because when we copy a lot of values around and
assign the var to multiple values throughout the program in multiple goroutines, we might get the panic message "concurrent map read and map write" indicating that the value is being written and read simultaneously because the same variable is being used at multiple places
func NewJsonObject ¶
func SetValueAndOverrideInJsonObjectByJPath ¶
func SetValueAndOverrideInJsonObjectByJPath(obj Typ, path string, valueToSet any, override bool) (Typ, error)
SetValueAndOverrideInJsonObjectByJPath will set a value in the Typ given its JPath. If the JPath contains non-existing keys then original object will be overridden based override parameter.
func SetValueInJsonObjectByJPath ¶
SetValueInJsonObjectByJPath will set a value in the Typ given its JPath.
func ToJsonObject ¶
ToJsonObject will convert interface{} object type to Typ using json.Marshal and json.Unmarshal
func (*Typ) AsByteSlice ¶
func (*Typ) FindKeyByValue ¶
func (*Typ) GetTopLevelElement ¶
GetTopLevelElement will return Top-Level element identified by key. If the key does not exist, nil is returned
func (*Typ) GetValueFromJsonObjectByJPath ¶
GetValueFromJsonObjectByJPath returns 3 values, in that order: dataType, value and an appError If there is any error when trying to get the value, the appError value contains the error and in that case the other two values should be ignored. In other cases the dataType indicates data type detected and the value can then be safely casted using value.(correspondingGoDataType) expression where `correspondingGoDataType` is the data type corresponding to dataType.
func (*Typ) HasTopLevelArray ¶
func (*Typ) IsNotEmpty ¶
func (Typ) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface IMPORTANT: PLEASE DO NOT CONVERT THE RECEIVER TO POINTER TYPE (DESPITE WARNINGS)
func (*Typ) PrettyString ¶
PrettyString will give the formatted string for this Typ
func (*Typ) Scan ¶
Scan implements the sql.Scanner interface. This method decodes a JSON-encoded value into the struct fields.
func (*Typ) SetNewTopLevelElement ¶
func (*Typ) SetValueByJPath ¶ added in v0.1.7
func (*Typ) StringOrBlankObject ¶ added in v0.1.9
func (*Typ) StringOrNil ¶ added in v0.1.8
func (*Typ) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.