I am using AWS Lambda to create my APIs and want to return an array's data in JSON format. However, when I call the lambda, it is able to return the required JSON data but it is coming as a string in double quotes. I tried running the same code in my Python IDE and everything works fine but when I try to return it in Lambda it is coming as a string.
Has this got something to do with how Lambda handles the return statement in Python functions?
This is how I'm returning data in my Lambda:
return {
'statusCode': 200,
'headers': {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": 'GET, POST, PUT, DELETE, OPTIONS'
},
'body': json.dumps(json_data,default = myconverter)
}
Here json_data is a python list which is populated with the data that is being retrieved from the database for the specific unique ID passed by the user and myconverter is the JSON encoder that I've written.
The output that I'm getting is:
{
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS"
},
"body": "[{\"Dp_Record_Id\": 2, \"DP_TYPE\": \"NSDL\", \"DP_ID\": \"40877589\", \"CLIENT_ID\": \"1232\", \"Default_flag\": \"Y\"}]"
}
Here, I want the "body" to just return an array of the data without double quotes, like this:
"body": [{\"Dp_Record_Id\": 2, \"DP_TYPE\": \"NSDL\", \"DP_ID\": \"40877589\", \"CLIENT_ID\": \"1232\", \"Default_flag\": \"Y\"}]
Please let me know if this is possible and how can it be done. Any help on this would be appreciated
