generated from linz/template-python-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feat/timestamps-whe…
…n-created-tde-1147
- Loading branch information
Showing
3 changed files
with
23 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
from typing import Any, Dict | ||
|
||
|
||
def dict_to_json_bytes(input_dict: Dict[str, Any]) -> bytes: | ||
""" | ||
Try to convert a `dict` into UTF-8 encoded `bytes` representing a JSON dictionary | ||
Examples: | ||
>>> dict_to_json_bytes({}) | ||
b'{}' | ||
>>> dict_to_json_bytes({"ā": "😀"}) # Unicode code points U+0101 and U+1F600 | ||
b'{"\xc4\x81": "\xf0\x9f\x98\x80"}' | ||
>>> json.loads(dict_to_json_bytes({"ā": "😀"})) | ||
{'ā': '😀'} | ||
""" | ||
return json.dumps(input_dict, ensure_ascii=False).encode("utf-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters