I did check a lot of different related Q'n'A (see linked questions), but none adressed my specific problem, mostly it was about different datatypes or requirements.
The attempt is to use this snippet to convert a nested map to json:
import json
#...
result = json.dumps(table_scan)
I am aware of the problems of this working correctly, but this doesnt seem to be the problem here. The above unfortunately gives me:
[ERROR] TypeError: Object of type Decimal is not JSON serializable
Traceback (most recent call last):
File "/var/task/lambda-function.py", line 61, in lambda_handler
result
File "/var/lang/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/var/lang/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/var/lang/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
How can I fix this without having to go into the (quite large) map for a 'manual' conversion.
(Application context more precisely: My python AWS lambda function performs scanning a DynamoDB with boto3
which gives me a (multi-layer) dict≈map. My goal is to convert this map to a json in order to return it (outwards) to a AWS API gateway. The items inside the Database come from the event parameters of the (inwards) API gateway.)