How can I create a record in Daml Hub's Live Data view?

I have the following Daml file

module Main where

data PayoutEvent = PayoutEvent with
  time : Time 
  amount : Decimal
    deriving (Eq, Show)

template Foo
  with
    owner : Party
    payouts : [PayoutEvent]
  where
    signatory owner

I deployed the resulting .dar to Daml Hub and want to instantiate a Foo using the Live Data view. According to the documentation records are defined as blocks containing their values, but I can’t seem to get the record right.

What is the format to create an array of the above PayoutEvent records?

When I try, for example, { "time": "2021-12-20T20:37:21.172Z", "amount": "10.0" } , I receive the following error:

JsonError: spray.json.DeserializationException: Can't read "{     \"time\": \"2021-12-20T20:37:21.172Z\",     \"amount\": \"10.0\"   } " as Record(IndexedSeq((time,TypePrim(PrimTypeTimestamp,IndexedSeq())), (amount,TypeNumeric(10))))

Thanks

Are you on the Live Data view or are you trying to submit a JSON payload using the HTTP JSON API directly?

By the way, these are the docs for the /v1/create endpoint:
https://docs.daml.com/json-api/index.html#http-request

Live Data view, in the Payouts input box

Your JSON encoding is perfectly fine and if you submit that via the JSON API it all works out. However, the hub UI is interpreting the JSON payload as a string not a JSON object and ends up submitting the following payload:

{
  "templateId": "3ca7f8d22cdda2f6c32aaee09c1f79068f31137f8534cc5a40055368b85bd03d:Main:Foo",
  "payload": {
    "payouts": [
      "{ \"time\": \"2021-12-20T20:37:21.172Z\", \"amount\": \"10.0\" }"
    ],
    "owner": "ledger-party-9185f5e7-60e7-4b18-93ed-a7b68e408f7d"
  }
}

which then (correctly) fails on the JSON API.

I don’t know the hub UI well enough to see if you can somehow convince it to interpret things as a JSON object instead.

1 Like

Thanks, @cocreature.
I spoke with @dtanabe and @sarah.breckenridge, and they confirmed this is a bug on the DamlHub UI. It should have shown nested input boxes to input the array elements and record fields. In the meantime, I’ll use the JSON or grpc API and build a small custom UI.