jsonnumber

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonnumber reads a JSON number as it is written, for the reads that must keep an integer past 2^53 exact or print a number as its source wrote it. encoding/json/v2 decodes every number that lands in an any as a float64 and has no counterpart to v1's UseNumber; AsWritten is that counterpart.

It is not the reader of proofs, keyrings or source answers, which is internal/strictjson, and it applies none of SPEC.md section 10.1's rules beyond what encoding/json/v2 makes.

Index

Constants

This section is empty.

Variables

View Source
var AsWritten = json.WithUnmarshalers(json.UnmarshalFromFunc(func(dec *jsontext.Decoder, v *any) error {
	if dec.PeekKind() != '0' {
		return errors.ErrUnsupported
	}
	raw, err := dec.ReadValue()
	if err != nil {
		return err
	}

	*v = jsontext.Value(bytes.Clone(raw))
	return nil
}))

AsWritten is an unmarshal option under which each JSON number decoded into an any, at any depth, is the jsontext.Value it is written as, and every other value decodes as it does by default. Such a number marshals again exactly as written, so "1.50" stays "1.50" and a ledger sequence is never re-printed as a float.

Functions

func Float64

func Float64(n jsontext.Value) (float64, error)

Float64 reads n, a number as written, as its nearest float64, as v1's Number.Float64 did.

func Int64

func Int64(n jsontext.Value) (int64, error)

Int64 reads n, a number as written, as an int64, as v1's Number.Int64 did: an error for a fraction, an exponent or a value past the int64 range.

func Uint64

func Uint64(n jsontext.Value) (uint64, error)

Uint64 reads n, a number as written, as a uint64: an error for a sign, a fraction, an exponent or a value past the uint64 range.

Types

This section is empty.

Jump to

Keyboard shortcuts

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