The best documentation that I know of for this is the source code, which defines the JSON encoding for ScriptData
.
The tags "int"
and "bytes"
encode those primitives. The tag "list"
encodes [ScriptData]
and the tag "map"
encodes [(ScriptData,ScriptData)]
. The "constructor"
tag with a "fields"
tag encodes Haskell constructors, where the integer following "constructor"
is the zero-based index to the constructor that is being used; the fields are encoded in order. Use the template Haskell PlutusTx.makeIsDataIndexed
or PlutusTx.unsafeMakeIsData
to create the encoding for a custom data type.
For example, for the type data Example = This Integer | That
, the value This 5
becomes {"constructor": 0, "fields": [{"int": 5}]}
and That
becomes {"constructor": 1, "fields": []}
.