Documentation
¶
Index ¶
- Constants
- func ExtractJsonFieldNames(v any) []string
- func FromBytes[T any](b []byte) (T, error)
- func FromFile[T any](path string) (T, error)
- func FromJSON[T any](r io.Reader) (T, error)
- func HandleEntity(data []byte, entity Entity) error
- func HandleEntityValue(value any, entity Entity)
- func HandlePrimitive(data []byte, primitive Primitive) error
- func HandlePrimitiveValue(value any, primitive Primitive)
- func String(value any) string
- func StructToMap(v any) (map[string]any, error)
- func ToBytes[T any](item T, opts ...Options) ([]byte, error)
- func ToFile[T any](item T, path string, opts ...Options) error
- func ToJSON[T any](item T, w io.Writer, opts ...Options) error
- type Entity
- type Options
- type Primitive
Constants ¶
const ( DefaultIndent = " " Extension = ".json" )
Variables ¶
This section is empty.
Functions ¶
func ExtractJsonFieldNames ¶
ExtractJsonFieldNames extracts the JSON field names from the given value
func HandleEntity ¶
HandleEntity parses the given JSON raw bytes using the handlers, according to its detected value type
func HandleEntityValue ¶
HandleEntityValue parses the given JSON marshaled value using the handlers, according to its detected value type
func HandlePrimitive ¶
HandlePrimitive parses the given JSON raw bytes using the handlers, according to its detected value type
func HandlePrimitiveValue ¶
HandlePrimitiveValue parses the given JSON marshaled value using the handlers, according to its detected value type
func StructToMap ¶
StructToMap efficiently converts a struct to map[string]any using sonic
func ToBytes ¶
ToBytes encodes the item to JSON and returns it as a byte slice with optional formatting options
Types ¶
type Entity ¶
type Entity interface {
// OnFloat Hook called when a float value is detected
OnFloat(floatValue float64)
// OnString Hook called when a string value is detected
OnString(stringValue string)
// OnBool Hook called when a boolean value is detected
OnBool(boolValue bool)
// OnNull Hook called when a null value is detected
OnNull()
// OnArray Hook called when an array value is detected
OnArray(arrayValue []any)
// OnObject Hook called when an object value is detected
OnObject(objectValue map[string]any)
}
Entity interface of an unknown JSON value
type Primitive ¶
type Primitive interface {
// OnValue Hook called when a primitive value is detected
OnValue(value any)
// OnNull Hook called when a null value is detected
OnNull()
// OnComplex Hook called when a object or array value is detected
OnComplex(complex any)
}
Primitive interface of a JSON primitive value