feat: add Decoder.UseNumber and the Number type
Test / test (push) Successful in 1m52s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-21 23:49:39 +02:00
parent 582222738b
commit ce0c1ebd9d
9 changed files with 320 additions and 4 deletions
+9
View File
@@ -36,6 +36,10 @@ type parser struct {
maxDepth int
depth int
// useNumber leaves the numbers a Number carries the literal, instead of
// the evaluated int64 or float64 the tree holds by default.
useNumber bool
root map[string]any
current map[string]any
headers map[string]bool
@@ -721,6 +725,11 @@ func (p *parser) parseAtom() (any, error) {
if err != nil {
return nil, p.errf("%s", err)
}
// The token's shape is validated either way; UseNumber only keeps the
// literal instead of the evaluated value.
if p.useNumber {
return Number(tok), nil
}
return v, nil
}