jsonv2

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalMarshalerTo

func MarshalMarshalerTo[T json.MarshalerTo](v T) ([]byte, error)

MarshalMarshalerTo provides a MarshalJSON implementation for any type that implements json.MarshalerTo. json.Marshal dispatches to MarshalJSONTo, so this doesn't recurse; the constraint is what guarantees that at compile time.

This is the entry point into v2 that establishes v1 options, per the package-level comment above.

func WriteField

func WriteField[T json.MarshalerTo](e *jsontext.Encoder, name string, v T) error

WriteField writes the object member name and then v's JSON encoding, so that the member is written and checked in one statement. A nil v is written as JSON null rather than dispatched to MarshalJSONTo: v1's reflection-based encoder already does this for a nil pointer, so writing null here keeps output identical to v1, rather than panicking on the types whose MarshalJSONTo assumes a non-nil receiver.

func WriteFieldArray

func WriteFieldArray[T json.MarshalerTo](e *jsontext.Encoder, name string, items []T) error

WriteFieldArray writes the object member name and then the JSON array of items.

func WriteFieldValue

func WriteFieldValue(e *jsontext.Encoder, name string, v any) error

WriteFieldValue is WriteField for values that don't implement json.MarshalerTo.

func WriteMarshalerToArray

func WriteMarshalerToArray[T json.MarshalerTo](e *jsontext.Encoder, items []T) error

WriteMarshalerToArray writes the JSON array of items to the encoder.

func WriteMarshalerToArrayOrNull

func WriteMarshalerToArrayOrNull[T json.MarshalerTo](e *jsontext.Encoder, items []T) error

WriteMarshalerToArrayOrNull is WriteMarshalerToArray but writes null for a nil slice, as encoding/json v1 does. Types whose pre-1.27 MarshalJSON returns "[]" for an empty value must keep using WriteMarshalerToArray.

Types

This section is empty.

Jump to

Keyboard shortcuts

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