json

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 4 Imported by: 0

README

json

Table of contents

Summary

This package provides generic, type-safe utilities for unmarshalling raw JSON into typed Go structs, along with testing helpers for managing deterministic sequences of JSON values and a simple serialiser with capability to serialise for specific group of interest.

Architecture

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPkg package error.
	ErrPkg = errors.New("json")
	// ErrJSON error.
	ErrJSON = fmt.Errorf("%w: JSON error", ErrPkg)
	// ErrMarshal error.
	ErrMarshal = fmt.Errorf("%w: marshal error", ErrJSON)
)

Functions

func MustBuildJSON

func MustBuildJSON[T any](data json.RawMessage) *T

MustBuildJSON factory, use it if the error is not worth handling.

func NewJSON

func NewJSON[T any](data json.RawMessage) (*T, error)

NewJSON factory.

Types

type RawMessageSequenceMap

type RawMessageSequenceMap struct {
	// contains filtered or unexported fields
}

RawMessageSequenceMap provides deterministic, per-key sequences of json.RawMessage values. It is useful for testing scenarios where each key should return a specific sequence of values on consecutive calls.

func NewRawMessageSequenceMap

func NewRawMessageSequenceMap(input map[string][]json.RawMessage) *RawMessageSequenceMap

NewRawMessageSequenceMap initialises and returns a new instance of JSONSequence.

func (*RawMessageSequenceMap) Next

Next returns the next json.RawMessage for the given key in the predefined sequence. If the key is unknown or has an empty sequence, it returns nil. If the sequence is exhausted, the last value is returned repeatedly.

type Serialiser added in v0.0.2

type Serialiser struct{}

Serialiser is a serialiser service.

func NewSerialiser added in v0.0.2

func NewSerialiser() *Serialiser

NewSerialiser a group specific factory.

func (*Serialiser) Serialise added in v0.0.2

func (s *Serialiser) Serialise(input any, groups []string) ([]byte, error)

Serialise a simple serialiser with capability to serialise for specific group of interest.

Jump to

Keyboard shortcuts

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