httpjson

package
v4.90.5 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 11 Imported by: 18 modules, 25 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

View Source
var (
	ErrCannotMarshal = errors.New("cannot marshal json")
)

Functions

func Parse added in v4.8.0

func Parse[T any](req *http.Request, maxSize int64) (T, error)

func RawWrite added in v4.22.0

func RawWrite(w io.Writer, obj any, opts ...json.Options) error

func Read added in v4.5.0

func Read[T any](resp *http.Response) (output T, err error)

func Stream added in v4.9.0

func Stream[T any](reader io.Reader, output chan<- T, key string, closeChan bool) error

Stream decodes JSON from a `reader` and send unmarshalled `T` to the given `output` chan `closeChan` make Stream to close the `output` channel once read. There is no guarantee that the `reader` wil be fully read. For HTTP Body you might want to drain it.

`key` supports three kinds of values: - "" => the reader contains a stream of objects like `{"id":12}{"id":34}{"id":56}`, e.g. processing a websocket - "." => the reader contains an array of objects like `[{"id":12},{"id":34},{"id":56}]` - <key name>" => the reader contains an array of objects at the given root key `{"items":[{"id":12},{"id":34},{"id":56}]}`.

func Write added in v4.5.0

func Write(ctx context.Context, w http.ResponseWriter, status int, obj any, opts ...json.Options)

func WriteArray added in v4.5.0

func WriteArray(ctx context.Context, w http.ResponseWriter, status int, array any, opts ...json.Options)

Types

This section is empty.

Jump to

Keyboard shortcuts

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