Documentation ¶
Overview ¶
Package json implements the JSON-Cadence specification: https://github.com/onflow/flow/blob/master/docs/json-cadence-spec.md
Index ¶
- func Decode(gauge common.MemoryGauge, b []byte, options ...Option) (cadence.Value, error)
- func Encode(value cadence.Value) ([]byte, error)
- func MustEncode(value cadence.Value) []byte
- func Prepare(v cadence.Value) jsonValue
- func PrepareType(typ cadence.Type, results TypePreparationResults) jsonValue
- type Decoder
- type Encoder
- type Option
- type TypePreparationResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode returns a Cadence value decoded from its JSON-encoded representation.
This function returns an error if the bytes represent JSON that is malformed or does not conform to the JSON Cadence specification.
func Encode ¶
Encode returns the JSON-encoded representation of the given value.
This function returns an error if the Cadence value cannot be represented as JSON.
func MustEncode ¶ added in v0.2.0
MustEncode returns the JSON-encoded representation of the given value, or panics if the value cannot be represented as JSON.
func Prepare ¶ added in v0.12.0
Prepare traverses the object graph of the provided value and constructs a struct representation that can be marshalled to JSON.
func PrepareType ¶ added in v1.0.0
func PrepareType(typ cadence.Type, results TypePreparationResults) jsonValue
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder decodes JSON-encoded representations of Cadence values.
func NewDecoder ¶
func NewDecoder(gauge common.MemoryGauge, r io.Reader) *Decoder
NewDecoder initializes a Decoder that will decode JSON-encoded bytes from the given io.Reader.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder converts Cadence values into JSON-encoded bytes.
func NewEncoder ¶
NewEncoder initializes an Encoder that will write JSON-encoded bytes to the given io.Writer.
type Option ¶ added in v0.24.4
type Option func(*Decoder)
func WithAllowUnstructuredStaticTypes ¶ added in v0.24.4
WithAllowUnstructuredStaticTypes returns a new Decoder Option which enables or disables if the decoding of a static type as a type ID (cadence.TypeID) is allowed
func WithBackwardsCompatibility ¶ added in v1.0.0
func WithBackwardsCompatibility() Option
WithBackwardsCompatibility returns a new Decoder Option which enables backwards compatibility mode, where the decoding of old versions of the JSON encoding is allowed