Documentation
¶
Overview ¶
Package jsonx is the JSON codec shared by the SDK's data models.
The models keep idiomatic Go field types (time.Time, decimal.Decimal) while the wire format follows the cross-SDK contract:
- decimals are written as bare JSON numbers, never quoted strings, and are read from numbers (or numeric strings) without losing printed digits;
- timestamps are read leniently (see ParseTime) and written as RFC 3339 UTC with a "Z" suffix;
- integer fields tagged `jsonx:"lenient"` also accept integral floats such as 3.0 and numeric strings.
Every other field is delegated to encoding/json, so nested models use their own MarshalJSON and UnmarshalJSON methods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidTimestamp = errors.New("invalid timestamp")
ErrInvalidTimestamp is wrapped by every ParseTime error.
Functions ¶
func FormatTime ¶
FormatTime formats t as RFC 3339 in UTC with a "Z" suffix and only the fractional digits needed.
func LenientInt ¶
func LenientInt(raw json.RawMessage, bits int) (int64, error)
LenientInt decodes an integer that may be encoded as a JSON integer, an integral float such as 3.0, or a numeric string. bits is the target width (32 or 64) used for the range check.
func Marshal ¶
Marshal encodes the struct v (or pointer to struct) as a JSON object with members in field order. Fields tagged omitempty are skipped when empty.
func ParseTime ¶
ParseTime parses an RFC 3339 style timestamp leniently and returns it in UTC.
It accepts a "T", "t" or space separator, 0 to 9 fractional-second digits (further digits are truncated), and a "Z" suffix, a numeric offset (+hh:mm, +hhmm or +hh) or no offset at all, which is read as UTC.
Types ¶
This section is empty.