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

jsonwire

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeWTF8Surrogate

func DecodeWTF8Surrogate(value string) (uint16, bool)

DecodeWTF8Surrogate returns the leading UTF-16 surrogate encoded as WTF-8.

func Marshal

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

Marshal follows JSON.stringify's string escaping rather than encoding/json's HTML-safe defaults. JavaScript leaves <, >, &, U+2028, and U+2029 literal.

func MarshalIndent

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

MarshalIndent matches JSON.stringify(value, null, 2)-style layout when called with ("", " "): Marshal's escaping plus json.Indent, which inserts whitespace without re-escaping.

func MarshalString

func MarshalString(value string) ([]byte, error)

MarshalString preserves WTF-8 encoded UTF-16 surrogates so Go can carry JavaScript strings produced by code-unit slicing through a JSON wire format.

func MessageRoleAndText

func MessageRoleAndText(raw json.RawMessage) (string, string)

MessageRoleAndText preserves upstream's concatenation of text blocks with no separator.

func UnmarshalString

func UnmarshalString(data []byte) (string, error)

UnmarshalString decodes a JSON string while retaining lone UTF-16 surrogates as WTF-8 so MarshalString can reproduce JSON.stringify output.

func UnmarshalStringToken

func UnmarshalStringToken(data []byte) (string, error)

UnmarshalStringToken decodes the first JSON string in a segment consumed by json.Decoder.Token. The segment may include separators and whitespace.

Types

type OrderedMember

type OrderedMember struct {
	Name  string
	Value any
}

OrderedMember is one name/value pair of an OrderedObject.

type OrderedObject

type OrderedObject []OrderedMember

OrderedObject is a JSON object that marshals its members in insertion order, matching JavaScript's object key ordering on the wire.

func (*OrderedObject) Delete

func (object *OrderedObject) Delete(name string)

Delete removes the first member with the given name, if present.

func (OrderedObject) MarshalJSON

func (object OrderedObject) MarshalJSON() ([]byte, error)

func (*OrderedObject) Set

func (object *OrderedObject) Set(name string, value any)

Set replaces the value of the first member with the given name in place, or appends a new member.

func (OrderedObject) Value

func (object OrderedObject) Value(name string) (any, bool)

Value returns the value of the first member with the given name.

Jump to

Keyboard shortcuts

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