Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion awslambdaric/lambda_runtime_marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

# simplejson's Decimal encoding allows '-NaN' as an output, which is a parse error for json.loads
# to get the good parts of Decimal support, we'll special-case NaN decimals and otherwise duplicate the encoding for decimals the same way simplejson does
# We also set 'ensure_ascii=False' so that the encoded json contains unicode characters instead of unicode escape sequences
class Encoder(json.JSONEncoder):
def __init__(self):
super().__init__(use_decimal=False)
super().__init__(use_decimal=False, ensure_ascii=False)

def default(self, obj):
if isinstance(obj, decimal.Decimal):
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
simplejson==3.17.2
simplejson==3.17.6
6 changes: 6 additions & 0 deletions tests/test_lambda_runtime_marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ def test_json_serializer_is_not_default_json(self):
self.assertTrue(hasattr(internal_json, "YOLO"))
self.assertFalse(hasattr(stock_json, "YOLO"))
self.assertTrue(hasattr(simplejson, "YOLO"))

def test_to_json_unicode_encoding(self):
response = to_json({"price": "£1.00"})
self.assertEqual('{"price": "£1.00"}', response)
self.assertNotEqual('{"price": "\\u00a31.00"}', response)
self.assertEqual(19, len(response.encode('utf-8'))) # would be 23 bytes if a unicode escape was returned