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
_10{_10 "type": "Void"_10}
Example
_10{_10 "type": "Void"_10}
Optional
_10{_10 "type": "Optional",_10 "value": null | <value>_10}
Example
_16// Non-nil_16_16{_16 "type": "Optional",_16 "value": {_16 "type": "UInt8",_16 "value": "123"_16 }_16}_16_16// Nil_16_16{_16 "type": "Optional",_16 "value": null_16}
Bool
_10{_10 "type": "Bool",_10 "value": true | false_10}
Example
_10{_10 "type": "Bool",_10 "value": true_10}
String
_10{_10 "type": "String",_10 "value": "..."_10}
Example
_10{_10 "type": "String",_10 "value": "Hello, world!"_10}
Address
_10{_10 "type": "Address",_10 "value": "0x0" // as hex-encoded string with 0x prefix_10}
Example
_10{_10 "type": "Address",_10 "value": "0x1234"_10}
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.
_10{_10 "type": "<type>",_10 "value": "<decimal string representation of integer>"_10}
Example
_10{_10 "type": "UInt8",_10 "value": "123"_10}
Fixed Point Numbers
[U]Fix64
Although fixed point numbers are implemented as integers, JSON-Cadence uses a decimal string representation for readability.
_10{_10 "type": "[U]Fix64",_10 "value": "<integer>.<fractional>"_10}
Example
_10{_10 "type": "Fix64",_10 "value": "12.3"_10}
Array
_10{_10 "type": "Array",_10 "value": [_10 <value at index 0>,_10 <value at index 1>_10 // ..._10 ]_10}
Example
_17{_17 "type": "Array",_17 "value": [_17 {_17 "type": "Int16",_17 "value": "123"_17 },_17 {_17 "type": "String",_17 "value": "test"_17 },_17 {_17 "type": "Bool",_17 "value": true_17 }_17 ]_17}
Dictionary
Dictionaries are encoded as a list of key-value pairs to preserve the deterministic ordering implemented by Cadence.
_10{_10 "type": "Dictionary",_10 "value": [_10 {_10 "key": "<key>",_10 "value": <value>_10 },_10 ..._10 ]_10}
Example
_16{_16 "type": "Dictionary",_16 "value": [_16 {_16 "key": {_16 "type": "UInt8",_16 "value": "123"_16 },_16 "value": {_16 "type": "String",_16 "value": "test"_16 }_16 }_16 ],_16 // ..._16}
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.
_13{_13 "type": "Struct" | "Resource" | "Event" | "Contract" | "Enum",_13 "value": {_13 "id": "<fully qualified type identifier>",_13 "fields": [_13 {_13 "name": "<field name>",_13 "value": <field value>_13 },_13 // ..._13 ]_13 }_13}
Example
_12{_12 "type": "Resource",_12 "value": {_12 "id": "0x3.GreatContract.GreatNFT",_12 "fields": [_12 {_12 "name": "power",_12 "value": {"type": "Int", "value": "1"}_12 }_12 ]_12 }_12}
Path
_10{_10 "type": "Path",_10 "value": {_10 "domain": "storage" | "private" | "public",_10 "identifier": "..."_10 }_10}
Example
_10{_10 "type": "Path",_10 "value": {_10 "domain": "storage",_10 "identifier": "flowTokenVault"_10 }_10}
Type Value
_10{_10 "type": "Type",_10 "value": {_10 "staticType": <type>_10 }_10}
Example
_10{_10 "type": "Type",_10 "value": {_10 "staticType": {_10 "kind": "Int",_10 }_10 }_10}
Capability
_10{_10 "type": "Capability",_10 "value": {_10 "path": <path>,_10 "address": "0x0", // as hex-encoded string with 0x prefix_10 "borrowType": <type>,_10 }_10}
Example
_16{_16 "type": "Capability",_16 "value": {_16 "path": {_16 "type": "Path",_16 "value": {_16 "domain": "public",_16 "identifier": "someInteger"_16 }_16 },_16 "address": "0x1",_16 "borrowType": {_16 "kind": "Int"_16 }_16 }_16}