DAML array of decimal in python?

Hi,

I have a field defined in my DAML template as

values: [Decimal]

In my python integration it is being received as [Decimal('200.0000000000'), Decimal( '186.0000000000'), Decimal('150.0000000000')].

The integration looks for this contract, picks it up and then tries to convert this into Json.

data = [ "readings" = request["values"] ]

The decimal array received this way doesn’t work - Object of type Decimal is not JSON serializable

How do I get this as [200.0000000000, 186.0000000000, 150.0000000000]

Appreciate your help.

Regards,
Manish

1 Like

I believe you can pass them over JSON as strings.

https://docs.daml.com/json-api/lf-value-specification.html#decimal

How are you building your Python integration? Which API are you calling, using which tooling? If you want JSON, I’d recommend using the JSON API.

1 Like

@ManishGrover is DAZL being too convenient for you?

Never fear, Python’s str to the rescue:

>>> str(Decimal('200.0000000000'))
'200.0000000000'
1 Like

thank you.

Used like this:

data = 
[ 
"readings" = [ str(d) for d in request["values"] ] 
]
1 Like