jsonx

package
v0.0.0-...-6729b5a Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

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

View Source
var ErrInvalidTimestamp = errors.New("invalid timestamp")

ErrInvalidTimestamp is wrapped by every ParseTime error.

Functions

func FormatTime

func FormatTime(t time.Time) string

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

func Marshal(v any) ([]byte, error)

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

func ParseTime(s string) (time.Time, error)

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.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal decodes the JSON object in data into the struct pointed to by v. Unknown members are ignored and absent members leave fields untouched. A JSON null leaves value fields untouched and sets pointer, slice and map fields to nil, as encoding/json does.

Types

This section is empty.

Jump to

Keyboard shortcuts

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