sortmap

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SortedMap

type SortedMap struct {
	// contains filtered or unexported fields
}

SortedMap is a map[string]any that serialises its keys in alphabetical order. This guarantees deterministic JSON output for tool schema definitions, which is required for stable prompt-cache fingerprints on providers that hash tool definitions (Anthropic, Bedrock).

Construct with NewSortedMap. The zero value is valid and marshals as {}.

func NewSortedMap

func NewSortedMap(m map[string]any) *SortedMap

NewSortedMap converts a map[string]any into a SortedMap whose keys are sorted alphabetically at every level of nesting. Nested map[string]any values and []any arrays are recursed so that all object nodes in the tree are also sorted. A nil or empty map produces a SortedMap that marshals as {}.

func (*SortedMap) MarshalJSON

func (sm *SortedMap) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. Keys are emitted in the order they were inserted (alphabetical, because NewSortedMap sorts them on construction).

Jump to

Keyboard shortcuts

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