How to use properly the "string" constructor in a Data object

playing around with the cardano-cli transaction hash-script-data command I always get the following error while trying to using the "string" constructor:

JSON object does not match the schema.
Expected a single field named "int", "bytes", "string", "list" or "map".
Unexpected object field(s): {"string":"hello"}

from which I can understand that it should be possible to use “string” as a field but I’m using it in some strange ways…

I’ve also tried to use it in some specific places, such as as a map key, assuming it would have emulated the JSON structure as follows:

{
	"constructor" : 0,
	"fields": [
		{
			"map": [
				{"k": {"string": "hello"}, "v":{"string": "world"} }
			]
		}
	]
}

without much success; changing the constructor instead works:

{
	"constructor" : 0,
	"fields": [
		{
			"map": [
				{"k": {"bytes": "abcdef"}, "v":{"int": 1} }
			]
		}
	]
}

so, as the title implies, my question is: How do I use the “string” type in a Data object?

The same problem (I think) popped up a few weeks ago:

To me it seems like a bug in cardano-api. They just forgot the string option.

Workaround would be to use a list of ints or something like that.

1 Like