JSON-Cadence Data Interchange Format
Version 0.3.1
JSON-Cadence is a data interchange format used to represent Cadence values as language-independent JSON objects.
This format includes less type information than a complete ABI, and instead promotes the following tenets:
- Human-readability - JSON-Cadence is easy to read and comprehend, which speeds up development and debugging.
- Compatibility - JSON is a common format with built-in support in most high-level programming languages, making it easy to parse on a variety of platforms.
- Portability - JSON-Cadence is self-describing and thus can be transported and decoded without accompanying type definitions (i.e. an ABI).
Values
Void
Example
Optional
Example
Bool
Example
String
Example
Address
Example
Integers
[U]Int
, [U]Int8
, [U]Int16
, [U]Int32
,[U]Int64
,[U]Int128
, [U]Int256
, Word8
, Word16
, Word32
, or Word64
Although JSON supports integer literals up to 64 bits, all integer types are encoded as strings for consistency.
While the static type is not strictly required for decoding, it is provided to inform client of potential range.
Example
Fixed Point Numbers
[U]Fix64
Although fixed point numbers are implemented as integers, JSON-Cadence uses a decimal string representation for readability.
Example
Array
Example
Dictionary
Dictionaries are encoded as a list of key-value pairs to preserve the deterministic ordering implemented by Cadence.
Example
Composites (Struct, Resource, Event, Contract, Enum)
Composite fields are encoded as a list of name-value pairs in the order in which they appear in the composite type declaration.
Example
Path
Example
Type Value
Example
Capability
Example
Functions
Function values can only be exported, they cannot be imported.
Example
Types
Simple Types
These are basic types like Int
, String
, or StoragePath
.
Example
Optional Types
Example
Variable Sized Array Types
Example
Constant Sized Array Types
Example
Dictionary Types
Example
Composite Types
Example
Field Types
Example
Parameter Types
Example
Initializer Types
Initializer types are encoded a list of parameters to the initializer.
Example
Function Types
Example
Reference Types
Example
Intersection Types
Example
Capability Types
Example
Enum Types
Example
Repeated Types
When a composite type appears more than once within the same JSON type encoding, either because it is recursive or because it is repeated (e.g. in a composite field), the composite is instead represented by its type ID.
Example