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 ¶
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 ¶
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 ¶
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.