Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/DAML array of decimal in python?Forum ↗

DAML array of decimal in python?

App Development5 posts406 views4 likesLast activity Jul 2020
MA
ManishGroverOP
Jul 2020 1

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

AN
anthony
Jul 2020

I believe you can pass them over JSON as strings.

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

BE
bernhard
Jul 2020 1

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.

LE
Leonid_Rozenberg
Jul 2020 1

@ManishGrover is DAZL being too convenient for you?

Never fear, Python’s str to the rescue:

>>> str(Decimal('200.0000000000'))
'200.0000000000'
MA
ManishGrover
Jul 2020 1

thank you.

Used like this:

data = 
[ 
"readings" = [ str(d) for d in request["values"] ] 
]
← Back to Discussions