jsonschemautil

package
v0.89.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceStringifiedJSON added in v0.89.0

func CoerceStringifiedJSON(schema *jsonschema.Schema, value any) (any, bool)

CoerceStringifiedJSON walks value alongside schema and, wherever the schema unambiguously expects an object or array but the value is a string containing valid JSON of that kind, replaces the string with the parsed value. It returns the (possibly mutated) value and whether anything changed. It never errors: on any ambiguity or parse failure it leaves the value untouched so that downstream schema validation produces its normal error. It exists to work around MCP clients that JSON-encode object-typed tool arguments as strings (see https://github.com/anthropics/claude-code/issues/25865).

func ExtractDefAsSchema

func ExtractDefAsSchema(jsonSchema, defName string) (string, error)

ExtractDefAsSchema extracts a specific definition from the $defs property of JSON schema by its name. The resulting schema's $defs will contain any other definitions that are referenced by the extracted definition. It returns the definition as a JSON schema string.

func ExtractReferencedDefs

func ExtractReferencedDefs(jsonSchema, defName string) (map[string]any, error)

ExtractReferencedDefs extracts all definitions referenced by a specific definition in the $defs property of JSON schema. It returns a map of definition names to their corresponding JSON schema definitions. The resulting map will include the specified definition and any other definitions that are referenced by it.

func MustExtractDefAsSchema

func MustExtractDefAsSchema(jsonSchema, defName string) string

MustExtractDefAsSchema wraps ExtractDefAsSchema and panics if an error occurs.

func MustExtractReferencedDefs

func MustExtractReferencedDefs(jsonSchema, defName string) map[string]any

MustExtractReferencedDefs wraps ExtractReferencedDefs and panics if an error occurs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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