jsonutil

package
v0.28.3 Latest Latest
Warning

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

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

Documentation

Overview

Package jsonutil provides JSON decoding helpers that preserve the exact value of every number in the input.

encoding/json decodes every JSON number into a float64 when the destination is an interface value. Tool arguments, tool results and history contents all travel through map[string]any on their way to and from the provider, so an integer wider than 53 bits (an account ID, a nanosecond timestamp) is silently rounded before the model ever sees it. The helpers here decode with json.Decoder.UseNumber and then hand back a float64 for every number a float64 can hold exactly, keeping json.Number only for the values that would otherwise be corrupted. Code that type-asserts float64 therefore keeps working for every value it works for today.

This package must not import the root gollem package: internal/convert already depends on gollem, and the root package needs these helpers too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, v any) error

Decode unmarshals data into v, preserving numbers that a float64 cannot represent exactly. Numbers decoded into an interface value become float64 as usual unless the conversion would change the value, in which case they stay json.Number.

func DecodeObject

func DecodeObject(data []byte) (map[string]any, error)

DecodeObject decodes a JSON object into a map, preserving numbers that a float64 cannot represent exactly. It returns an error when data is not a JSON object.

func MarshalIndentNoEscape

func MarshalIndentNoEscape(v any, prefix, indent string) ([]byte, error)

MarshalIndentNoEscape marshals v as indented JSON without escaping the three HTML-significant characters "<", ">" and "&". encoding/json replaces them with their six-character unicode escapes by default, which is invisible to a JSON parser but not to a reader: this output is embedded verbatim into a system prompt, where the model reads the escape sequences instead of the characters the schema author wrote.

Types

This section is empty.

Jump to

Keyboard shortcuts

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