SuiJSON is a JSON-based format with restrictions that allow Sui to align JSON inputs more closely with Move call arguments.
This table shows the restrictions placed on JSON types to make them SuiJSON compatible:
|JSON||SuiJSON Restrictions||Move Type Mapping|
|Number||Must be unsigned integer||U8|
(U64 is encoded as String)
(U128 is encoded as String)
(U256 is encoded as String)
Unsigned Integer (256 bit max)
|Array||Must be homogeneous JSON and of SuiJSON type||Vector|
Type coercion reasoning
Due to the loosely typed nature of JSON/SuiJSON and the strongly typed nature of Move types, you sometimes need to overload SuiJSON types to represent multiple Move types.
SuiJSON::Number can represent both U8 and U32. This means you have to coerce and sometimes convert types.
Which type you coerce depends on the expected Move type. For example, if the Move function expects a U8, you must have received a
SuiJSON::Number with a value less than 256. More importantly, you have no way to easily express Move addresses in JSON, so you encode them as hex strings prefixed by
Additionally, Move supports U128 and U256 but JSON doesn't. As a result Sui allows encoding numbers as strings.
Type coercion rules
|Move Type||SuiJSON Representations||Valid Examples||Invalid Examples|
|U8||Supports 3 formats:|
|U16||Three formats are supported|
|U32||Three formats are supported|
|U64||Supports two formats|
|U128||Two formats are supported|
|U256||Two formats are supported|
|Address||32 byte hex string prefixed with |
|ObjectID||32 byte hex string prefixed with ||Similar to above|
|Identifier||Typically used for module and function names. Encoded as one of the following:|
|Vector<Move Type>||Homogeneous vector of aforementioned types including nested vectors of primitive types (only "flat" vectors of ObjectIDs are allowed)|
|Vector<U8>||For convenience, Sui allows:|
U8 vectors represented as UTF-8 (and ASCII) strings.