Documentation
¶
Overview ¶
Package jsonvalue renders a decoded JSON value for a human-readable diagnostic.
Two plan-time validators check an author's JSON against a declared schema and have to say, in a sentence, what they found where they expected something else: the SDK's appleschemas/profiles against Apple's payload key table, and internal/common/aischemas against a vendor's JSON Schema. The schema languages share nothing, but the vocabulary for naming a decoded value does — and getting it wrong is how a diagnostic ends up reading "expected a integer, found 1e+09".
Everything here operates on the output of encoding/json, so a number arrives as float64 unless the decoder was set to use json.Number; both are handled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Article ¶
Article prefixes a declared type name for readability in a sentence.
The vowel set deliberately omits "u": every name this is called with is a JSON or Apple payload type (object, array, integer, number, string, boolean, null, dictionary, data, date, real, any), none of which begins with u, and "a unit"-shaped words would take "a" rather than "an" anyway.
func Describe ¶
Describe names a value's JSON type for a diagnostic, with its article, so it drops into a sentence as "expected a string, found an array".
func FormatNumber ¶
FormatNumber renders a JSON number without exponent notation, so a large integer reads as the digits the author wrote.
The int64 path is taken only inside int64's range, and that bound is this function's own concern rather than IsWhole's: converting an out-of-range float to int64 is implementation-defined in Go, so 1e30 would otherwise print as int64's minimum instead of its own digits. The comparison is strict against MaxInt64 because the constant rounds up to 2^63 as a float64, which does not fit.
func IsWhole ¶
IsWhole reports whether a JSON number has no fractional part. Integer-ness is a property of the value, not of any machine type it might be squeezed into, so 1e30 is as whole as 3 — which is why this deliberately carries no int64 bound and every caller that converts to int64 checks that bound itself. The round-trip comparison this replaces, `number == float64(int64(number))`, folded the two questions together and so called 1e30 fractional on amd64, where an out-of-range float-to-int64 conversion is implementation-defined: a schema declaring `"type":"integer"` then reported 1e30 as the self-contradictory "expected an integer, found a whole number".
Types ¶
This section is empty.