json-unescape/json_unescape/__init__.py

11 lines
283 B
Python
Raw Normal View History

2024-07-02 14:30:25 +00:00
import json
def escape_json(json_str: str) -> str:
nested_object: dict = {"key": json_str}
return json.dumps(nested_object)
def unescape_json(json_str: str) -> str:
nested_json_string: str = '{"key": ' + json_str + '}'
return json.loads(nested_json_string)["key"]