utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCollectionFromJSON added in v0.2.0

func LoadCollectionFromJSON[T any](jsonString string) ([]T, error)

LoadCollectionFromJSON unmarshals a JSON array into a []T. Any json.Unmarshal error is returned as-is.

func LoadCollectionFromJSONFile added in v0.2.0

func LoadCollectionFromJSONFile[T any](fileName string) ([]T, error)

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

func LoadObjectFromJSON[T any](jsonString string) (*T, error)

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

func LoadObjectFromJSONFile[T any](fileName string) (*T, error)

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.

func ToJSON added in v0.2.0

func ToJSON(entity interface{}) (string, error)

ToJSON marshals entity to a JSON string. Marshal errors are wrapped so callers can distinguish them from downstream failures.

Types

This section is empty.

Jump to

Keyboard shortcuts

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