jsonutil

package
v0.85.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

kit/jsonutil

github.com/vormadev/vorma/kit/jsonutil

Thin wrappers around encoding/json with consistent error context.

Import

import "github.com/vormadev/vorma/kit/jsonutil"

When To Use

Use this package when you want simple JSON encode/decode helpers with stable wrapped error messages.

If you need advanced behavior (streaming decoders, DisallowUnknownFields, custom encoder options), use encoding/json directly.

Examples

type User struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

payload, err := jsonutil.Serialize(User{Name: "Ada", Age: 30})
if err != nil {
	return err
}

user, err := jsonutil.Parse[User](payload)
if err != nil {
	return err
}
_ = user

Error Contract

  • Serialize returns error encoding JSON: ... on marshal failure.
  • Parse[T] returns the zero value of T plus error decoding JSON: ... on unmarshal failure.

API Reference

  • type JSONString string
  • func Serialize(v any) ([]byte, error)
  • func Parse[T any](data []byte) (T, error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse[T any](data []byte) (T, error)

func Serialize

func Serialize(v any) ([]byte, error)

Types

type JSONString

type JSONString string

JSONString is a semantic marker type for JSON payload strings.

Jump to

Keyboard shortcuts

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