MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / DecodeJSONKeepingNumbers

Function DecodeJSONKeepingNumbers

internal/models/fields_json.go:45–55  ·  view source on GitHub ↗

DecodeJSONKeepingNumbers is DecodeFieldsJSON for any target: v must be a pointer, as for json.Unmarshal. The range check covers numbers held in interface{} slots (any, map[string]any, []any), which are the only slots UseNumber affects; a typed float64 or int destination is range-checked by the decod

(data []byte, v any)

Source from the content-addressed store, hash-verified

43// UseNumber affects; a typed float64 or int destination is range-checked by
44// the decoder itself, as it always was.
45func DecodeJSONKeepingNumbers(data []byte, v any) error {
46 dec := json.NewDecoder(bytes.NewReader(data))
47 dec.UseNumber()
48 if err := dec.Decode(v); err != nil {
49 return err
50 }
51 if _, err := dec.Token(); err != io.EOF {
52 return fmt.Errorf("invalid JSON: trailing data after the top-level value")
53 }
54 return checkNumbersFitFloat64(v)
55}
56
57// checkNumbersFitFloat64 refuses a json.Number that json.Unmarshal would have
58// refused when decoding into an interface: one ParseFloat reports out of

Callers 15

updateFieldsMethod · 0.92
ItemStateHashMethod · 0.92
droppedKeysPresentFunction · 0.92
addedKeysConflictFunction · 0.92
decodeFieldsBlobFunction · 0.92
migrateCopyFieldsMethod · 0.92
mergeFieldsPatchFunction · 0.92
dropBlankStringKeysFunction · 0.92
coerceValueFunction · 0.92
CopyItemPreflightMethod · 0.92
FormatFieldSummaryFunction · 0.92

Calls 2

checkNumbersFitFloat64Function · 0.85
DecodeMethod · 0.65

Tested by 1