Help us shape the future of Go! Take the 2026 Go Developer Survey

wirejson

package
v1.146.1 Latest Latest
Warning

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

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

Documentation

Overview

Package wirejson is the one encoder for JSON the platform answers with: every REST response body and every MCP tool result (#1832).

It encodes exactly as encoding/json does, with one difference: a nil slice is an empty array, [], never null. Go gives a slice that nothing was appended to the value nil, and so does a lookup of a map key that is not there, and encoding/json writes that as null. A caller iterating the field then fails on it: a managed script's `for it in section.get("items", [])` gets None, because the key is present, and stops with "NoneType value is not iterable". Normalizing here covers every slice field a response carries, the ones written before this package and every one added after, where a fix per field covers only the fields someone remembered.

A nil map is still null, and a nil []byte is "" (the empty base64 string) rather than null. json.RawMessage keeps its own encoding: a nil one is null.

test/structure holds every response to this encoder: a function that writes an http.ResponseWriter, returns an MCP tool result, or builds its text block may not call encoding/json's Marshal, MarshalIndent or NewEncoder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

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

Encode writes the JSON encoding of v to w followed by a newline, as json.NewEncoder(w).Encode(v) does.

func Marshal

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

Marshal returns the JSON encoding of v, as json.Marshal does, with every nil slice written as [].

func MarshalIndent

func MarshalIndent(v any, prefix, indent string) ([]byte, error)

MarshalIndent is Marshal with each element on its own line, as json.MarshalIndent formats it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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