Skip to content

Commit 8e3bb0c

Browse files
authored
Merge pull request #88 from mdsakalu/main
Use unicode chars instead of escape sequences in json encoder output and bump simplejson version
2 parents 186003d + 44300b7 commit 8e3bb0c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Diff for: awslambdaric/lambda_runtime_marshaller.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
# simplejson's Decimal encoding allows '-NaN' as an output, which is a parse error for json.loads
1414
# 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
15+
# We also set 'ensure_ascii=False' so that the encoded json contains unicode characters instead of unicode escape sequences
1516
class Encoder(json.JSONEncoder):
1617
def __init__(self):
17-
super().__init__(use_decimal=False)
18+
super().__init__(use_decimal=False, ensure_ascii=False)
1819

1920
def default(self, obj):
2021
if isinstance(obj, decimal.Decimal):

Diff for: requirements/base.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
simplejson==3.17.2
1+
simplejson==3.17.6

Diff for: tests/test_lambda_runtime_marshaller.py

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ def test_json_serializer_is_not_default_json(self):
3737
self.assertTrue(hasattr(internal_json, "YOLO"))
3838
self.assertFalse(hasattr(stock_json, "YOLO"))
3939
self.assertTrue(hasattr(simplejson, "YOLO"))
40+
41+
def test_to_json_unicode_encoding(self):
42+
response = to_json({"price": "£1.00"})
43+
self.assertEqual('{"price": "£1.00"}', response)
44+
self.assertNotEqual('{"price": "\\u00a31.00"}', response)
45+
self.assertEqual(19, len(response.encode('utf-8'))) # would be 23 bytes if a unicode escape was returned

0 commit comments

Comments
 (0)