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 ¶
Encode writes the JSON encoding of v to w followed by a newline, as json.NewEncoder(w).Encode(v) does.
Types ¶
This section is empty.