user2248: By following the alonzo-testnet exercises, I'm right now having to build a transaction with cardano-cli. One of the arguments necessary to consume a script is the datum, another is the redeemer, both of which should be in a JSON file (or value).
Is there any reference of how Data should be expressed in JSON? Because I tried converting it with Data.Aeson in Haskell, but received the following error
JSON object does not match the schema.
Expected a single field named "int", "bytes", "string", "list" or "map".
Unexpected object field(s): {"contents":{"getPubKeyHash":"3e7181860513a17dfa44d69232429e5c328e79c748d4a176950c42b6"},"tag":"Collect"}

Also, is there any library to make my life easier, so I can be able to easily convert my redeemers into JSON?

user2248: Reading some old messages in discord, someone mentioned that I could use encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData data), taken from here, so I made a redeemerJSON function defined as follows:
redeemerJSON :: DistributionRedeemer -> ByteString
redeemerJSON dr =
  encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData dr))

Of course some imports are necessary, but I believe you can use this same approach for the datum and other script parameters too.

2248: <p>By following the alonzo-testnet exercises, I'm right now having to build a transaction with <code>cardano-cli</code>. One of the arguments necessary to consume a script is the datum, another is the redeemer, both of which should be in a JSON file (or value).</p>
<p>Is there any reference of how <code>Data</code> should be expressed in JSON? Because I tried converting it with Data.Aeson in Haskell, but received the following error</p>
<pre><code>JSON object does not match the schema.
Expected a single field named &quot;int&quot;, &quot;bytes&quot;, &quot;string&quot;, &quot;list&quot; or &quot;map&quot;.
Unexpected object field(s): {&quot;contents&quot;:{&quot;getPubKeyHash&quot;:&quot;3e7181860513a17dfa44d69232429e5c328e79c748d4a176950c42b6&quot;},&quot;tag&quot;:&quot;Collect&quot;}
</code></pre>
<p>Also, is there any library to make my life easier, so I can be able to easily convert my redeemers into JSON?</p>
 2248: <p>Reading some old messages in discord, someone mentioned that I could use <code>encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData data)</code>, taken from <a href="https://github.com/input-output-hk/Alonzo-testnet/blob/main/resources/plutus-sources/plutus-helloworld/app/plutus-helloworld-bytestring.hs#L43" rel="nofollow noreferrer">here</a>, so I made a <code>redeemerJSON</code> function defined as follows:</p>
<pre><code>redeemerJSON :: DistributionRedeemer -&gt; ByteString
redeemerJSON dr =
  encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (PlutusTx.toData dr))
</code></pre>
<p>Of course some imports are necessary, but I believe you can use this same approach for the datum and other script parameters too.</p>
