utils

package
v0.1.1 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

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

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

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

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

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