简体   繁体   中英

How to convert json object returned from browser to string in python lambda function

Am a beginner to AWS, suppose I received a json object as following from client

[{'bid': 1, 'bodypart_name': 'Chest', 'image': 'image'}]

on which service of aws I would receive this object (am assuming it would get received in API gateway) and how should I convert that object to string in my lambda python function. Any help would be much appreciated

Ask your client where they are sending this json request. If you are getting this on lambda you'll want to extract the values not turn the whole json object into a string. You can get the values like this:

json_obj = [{'bid': 1, 'bodypart_name': 'Chest', 'image': 'image'}]
for i in json_obj:
    print(i['bid'])
    print(i['bodypart_name'])
    print(i['image'])

The reason for the for loop is to capture multiple list objects. If you are sure you will only get 1 object inside list you can use json_obj[0]['bid'] without loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM