Documentation
¶
Overview ¶
Package utils contains small JSON helpers used alongside the nullable and not-null types from package types.
LoadObjectFromJson / LoadCollectionFromJson parse a JSON string into a strongly-typed value; the *FromJsonFile variants read the payload from disk first. ToJson is the inverse — it serializes an arbitrary value and returns both the JSON string and any encoding/json error so callers can react to marshalling failures.
Index ¶
- func LoadCollectionFromJson[T any](jsonString string) ([]T, error)
- func LoadCollectionFromJsonFile[T any](fileName string) ([]T, error)
- func LoadObjectFromJson[T any](jsonString string) (*T, error)
- func LoadObjectFromJsonFile[T any](fileName string) (*T, error)
- func ToJson(entity interface{}) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadCollectionFromJson ¶
LoadCollectionFromJson unmarshals a JSON array into a []T. Any json.Unmarshal error is returned as-is.
func LoadCollectionFromJsonFile ¶
LoadCollectionFromJsonFile reads fileName from disk and unmarshals the contents into a []T. Read and unmarshal errors are wrapped with the file name for easier diagnosis.
func LoadObjectFromJson ¶
LoadObjectFromJson unmarshals a JSON object into a fresh T and returns a pointer to it. Any json.Unmarshal error is returned as-is.
func LoadObjectFromJsonFile ¶
LoadObjectFromJsonFile reads fileName from disk and unmarshals the contents into a fresh T. Read and unmarshal errors are wrapped with the file name for easier diagnosis.
Types ¶
This section is empty.