jsonObject

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

func FillFromJsonObject(j Typ, pointerToStruct any) error

FillFromJsonObject will take a jsonObject Typ and fill the pointerToStruct with the value extracted from the jsonObject

func ValidateJPathSyntax

func ValidateJPathSyntax(path string) error

ValidateJPathSyntax validates JPath syntax (not against any specific Typ)

Types

type StringAnyMap

type StringAnyMap map[string]any

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 NewJsonObject(key string, value interface{}) Typ

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

func SetValueInJsonObjectByJPath(obj Typ, path string, valueToSet any) (Typ, error)

SetValueInJsonObjectByJPath will set a value in the Typ given its JPath.

func ToJsonObject

func ToJsonObject(v interface{}) (Typ, error)

ToJsonObject will convert interface{} object type to Typ using json.Marshal and json.Unmarshal

func (*Typ) AsByteSlice

func (j *Typ) AsByteSlice() []byte

func (*Typ) FindKeyByValue

func (j *Typ) FindKeyByValue(value interface{}) string

func (*Typ) GetTopLevelElement

func (j *Typ) GetTopLevelElement(key string) any

GetTopLevelElement will return Top-Level element identified by key. If the key does not exist, nil is returned

func (*Typ) GetValueFromJsonObjectByJPath

func (j *Typ) GetValueFromJsonObjectByJPath(path string) (string, any, appError.Typ)

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 (j *Typ) HasTopLevelArray() bool

func (*Typ) IsEmpty

func (j *Typ) IsEmpty() bool

func (*Typ) IsNotEmpty

func (j *Typ) IsNotEmpty() bool

func (Typ) MarshalJSON

func (j Typ) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface IMPORTANT: PLEASE DO NOT CONVERT THE RECEIVER TO POINTER TYPE (DESPITE WARNINGS)

func (*Typ) PrettyString

func (j *Typ) PrettyString() string

PrettyString will give the formatted string for this Typ

func (*Typ) Scan

func (j *Typ) Scan(value interface{}) error

Scan implements the sql.Scanner interface. This method decodes a JSON-encoded value into the struct fields.

func (*Typ) SetNewTopLevelElement

func (j *Typ) SetNewTopLevelElement(key string, value interface{}) (replacedExistingKey bool)

func (*Typ) SetValueByJPath added in v0.1.7

func (j *Typ) SetValueByJPath(path string, valueToSet any) error

func (*Typ) String

func (j *Typ) String() string

func (*Typ) StringOrBlankObject added in v0.1.9

func (j *Typ) StringOrBlankObject() string

func (*Typ) StringOrNil added in v0.1.8

func (j *Typ) StringOrNil() *string

func (*Typ) UnmarshalJSON

func (j *Typ) UnmarshalJSON(dataToUnmarshal []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Typ) Value

func (j *Typ) Value() (driver.Value, error)

Value implements the driver.Valuer interface. This method returns the JSON-encoded representation of the struct.

Jump to

Keyboard shortcuts

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