jsonkit

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package jsonkit is how anfra reads and writes JSON: encoding/json/v2 with one set of options, used by every package, so a value is encoded the same way whichever door it leaves by. Don't import encoding/json or encoding/json/v2 elsewhere; depguard refuses it. See docs/designs/json.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Marshal is v as JSON.

func MarshalEncode

func MarshalEncode(enc *jsontext.Encoder, v any) error

MarshalEncode writes v to enc, with enc's options: for a MarshalJSONTo method, so the options of whatever is encoding it reach inside.

func MarshalIndent

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

MarshalIndent is v as JSON, indented by two spaces, for a file people read.

func MarshalWrite

func MarshalWrite(w io.Writer, v any) error

MarshalWrite writes v as JSON to w.

func Unmarshal

func Unmarshal(b []byte, v any) error

Unmarshal reads the JSON value b into v.

func UnmarshalRead

func UnmarshalRead(r io.Reader, v any) error

UnmarshalRead reads the one JSON value in r, to its end, into v.

func UnmarshalReadStrict added in v0.9.0

func UnmarshalReadStrict(r io.Reader, v any) error

UnmarshalReadStrict is UnmarshalRead that also refuses a member v has no field for: for a request a server reads as its whole contract, where an unknown member is the caller's mistake, not something to ignore. A server that validates against a schema (apikit) refuses them there already.

func Valid

func Valid(b []byte) bool

Valid reports whether b is one JSON value, as Unmarshal would read it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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