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 ¶ added in v0.2.0
LoadCollectionFromJSON unmarshals a JSON array into a []T. Any json.Unmarshal error is returned as-is.
func LoadCollectionFromJSONFile ¶ added in v0.2.0
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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
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.