Skip to main content

Module gojson

Module gojson 

Source
Expand description

Go encoding/json for the plugin RPC contract.

Most sdk/pluginapi structs carry no json tags, so the wire names are the Go field names (AuthID, StorageJSON). Encoding follows json.Marshal: fields in declaration order, omitempty, HTML-escaped strings, []byte as padded standard base64, maps with sorted keys, time.Time as RFC 3339 with nanoseconds. Decoding follows json.Unmarshal: a key matches its field exactly or, failing that, case-insensitively; unknown keys are ignored; the last duplicate wins; null leaves scalars alone and clears slices and maps; numbers into integer fields must be integer literals.

Decoding walks a Node tree that keeps every object member and number literal, and follows Go’s decode-into-existing rules: struct fields and map keys merge into what is already there (a map element itself is decoded fresh), a pointer decodes into its pointee, a slice reuses its elements.

Structs are declared with go_struct!. []byte is bytes::Bytes; map[string]any and any are serde_json::Value.

ponytail: an empty slice, map or []byte encodes as null (Go’s nil). Fields Go builds non-nil while empty use NonNil.

Structs§

DecodeError
GoTime
time.Time; None is the zero time (0001-01-01T00:00:00Z).
NonNil
A slice or map Go builds non-nil even when empty: encodes [] / {}.
NonNilBytes
A []byte Go builds non-nil (for example from io.ReadAll): encodes "" when empty instead of null.
ObjWriter
Writes one JSON object field by field.
RawJson
json.RawMessage: marshalled compact with HTML escaping; null when empty.

Enums§

Node

Traits§

GoJson
A value with Go encoding/json semantics.
GoStruct
A Go struct: encodes its fields in order and decodes them by name.

Functions§

decode_field_value
Decodes one field into its current value.
decode_struct
Decodes an object into a fresh struct.
decode_struct_into
Decodes an object member by member into an existing struct; later duplicates decode over earlier ones.
encode_any
Go’s encoding of a value decoded into any.
from_slice
json.Unmarshal of a complete document.
from_slice_first
json.NewDecoder(bytes.NewReader(raw)).Decode: the first value; see parse_first.
in_field
Adds the struct field to a decode error, like Go’s UnmarshalTypeError: the innermost struct’s name and the field path from the outermost struct (array indexes and map keys are not part of it).
number_error
A number that does not fit the numeric go_type (Go "number " + literal).
parse
json.Unmarshal’s syntax pass and value tree.
parse_first
json.NewDecoder(r).Decode over a complete reader: the first value only, with anything after it left unread; a truncated value is unexpected EOF and input without any value EOF.
to_vec
json.Marshal.
type_error
A value of the wrong JSON kind for go_type. Go names a number without its literal here; number_error is the numeric-range case that includes it.

Type Aliases§

Header
http.Header and url.Values.
Metadata
map[string]any.
StringMap
map[string]string.