jsonObject

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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)

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) String

func (j *Typ) String() 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