title: Error with AWS Lambda event parsing - invalid JSON data
body: <p>So I have a weird issue with AWS Lambda. I've got an endpoint that I am POST'ing to with a cookie, but the event JSON for some reason is invalid as it contains single quotes instead of JSON spec double quotes, which in turn causes an exception with body = json.loads(event['body']) so I've resorted to using ast for input parsing:</p>
  <pre><code>def lambda_handler(event, context):
  
      body = ast.literal_eval(str(event)['body'])
  </code></pre>
  <p>which is throwing an exception:</p>
  <pre><code>[ERROR] TypeError: string indices must be integers
  Traceback (most recent call last):
    File &quot;/var/task/app.py&quot;, line 23, in lambda_handler
      body = ast.literal_eval(str(event)['body'])
  </code></pre>
  <p>Here is what the input event looks like from CloudWatch:</p>
  <pre><code>2021-05-23T02:22:33.437+00:00
  {'version': '2.0', 'routeKey': 'POST /core', 'rawPath': '/Prod/core', 'rawQueryString': '', 'headers': {'accept-encoding': 'gzip', 'content-length': '994', 'content-type': 'application/json; charset=UTF-8', 'host': 'mrmyi8psq3.execute-api.us-east-2.amazonaws.com', 'user-agent': 'Dart/2.10 (dart:io)', 'x-amzn-trace-id': 'Root=1-60a9bc68-638af3f87db7635e129612a0', 'x-forwarded-for': '106.204.193.37', 'x-forwarded-port': '443', 'x-forwarded-proto': 'https'}, 'requestContext': {'accountId': '246891114792', 'apiId': 'mrmyi8psq3', 'domainName': 'mrmyi8psq3.execute-api.us-east-2.amazonaws.com', 'domainPrefix': 'mrmyi8psq3', 'http': {'method': 'POST', 'path': '/Prod/core', 'protocol': 'HTTP/1.1', 'sourceIp': '106.204.193.37', 'userAgent': 'Dart/2.10 (dart:io)'}, 'requestId': 'fwpgajclCYcEMtg=', 'routeKey': 'POST /core', 'stage': 'Prod', 'time': '23/May/2021:02:22:32 +0000', 'timeEpoch': 1621736552901}, 'body': '{&quot;message&quot;:&quot;test message&quot;,&quot;cookie&quot;:&quot;eyJraWQiOiJOVlwvSXB5V0xGblRvTXBVaHhqTUVDUXQ3UWFxOVNxcVUxVkFIa2p4eFwvT3M9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJlNTljZGZhYS05OWY5LTQ3OTAtYWRkZi1lOWM4YTgwMTE1ZWMiLCJhdWFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMl91dGlsM2hYN0kiLCJjb2duaXRvOnVzZXJuYW1lIjoiZTU5Y2RmYWEtOTlmOS00NzkwLWFkZGYtZTljOGE4MDExNWVjIiwiZXhwIjoxNjIxNzQwMTIxLCJpYXQiOjE2MjE3MzY1MjEsImVtYWlsIjoicGF2YW55YWRhdkBob3RtYWlsLmNvbSJ9.kK6NRpgiLNmgrzuB91APy15fvJfDt2FtmZQKvOLQJAK8J522OH9hiD4Sroh_F_DivYO98exseEV99FVuyiAB7I70QpYeZUy2M0OF_VSt9AZ8cM_XUN8gf1NHNQoIJlsRNOcok6hJn4Bp7mYhZuyQmzpFk1Hq9joMcjvHBXa0iGBS6stp-2bVH23yVrrYYeDl0lyUfVLUcwwT3BP7jZDcVDcWpfqZYNR5yU4o7Tw0oZKESNCxIr3Hh1EZGMUJwhb-RsSKb9nMafQYJQ-VtFNRj5rlJGf_M1QYwvli-g82p7C9Kf6SbgsjDYKxsjdxZAyouVaXnaL6QgAOLCEMxopTLA&quot;}', 'isBase64Encoded': False}
  </code></pre>
  <p>Any thoughts would be greatly appreciated!</p>