Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass integer value in json serializable Python Object

I am new to Python and have been trying to resolve this.
There is an AWS lambda function written in Python which calls a REST point like this:

requests.post(Url,headers=Headers,data=Payload)

Payload in the above call is being passed like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Payload='[{"Code": "'+someCode+'","version": "v1","itemNumber": 1,"referenceId": "'+referenceId+'","alertBody": {"customerId": "'+customerId+'"},"Context":{"Id":"'+str(payload['body']['State']['Id'])+'","Name":"Payment","Expiration":0,"Action":"","sourceTimestamp":"'+ str(int(currentTime.timestamp()))+'","sourceApp":"someApp"}}]'

However, due to a recent change in the schema at the API end where we post this Payload to, It has stopped working. The API is now expecting the "sourceTimestamp":"’+ str(int(currentTime.timestamp()))+’" field to be sent as an Integer and not String (currently it is being sent as String as shown in the payload above)

Can someone please guide me how to fix it and send the timestamp filed as an integer and not string? I want adhere to the payload format as above.

>Solution :

Json integers must be given without double quoting them. So simply removing the double quotes arround str(int(currentTime.timestamp())) would work for your case

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading