Compare commits

..

2 Commits

Author SHA1 Message Date
96bb1fce8e feat: added documentation 2024-07-02 16:32:44 +02:00
adef56790f feat: implemented functions 2024-07-02 16:30:25 +02:00
4 changed files with 30 additions and 9 deletions

View File

@ -1,3 +1,22 @@
# Json-Unescape
Unescape json string, which is escaped for json. This is usually necessarry for webscraping.
Unescape json string, which is escaped for json. This is usually necessarry for webscraping.
## Installation
```bash
pip install json-unescape
```
## Usage
```python
>>> from json_unescape import escape_json, unescape_json
>>> escape_json('{"foo": "bar,,,eee"}')
'{"key": "{\\"foo\\": \\"bar,,,eee\\"}"}'
>>> unescape_json(escape_json('{"key": "{\\"foo\\": \\"bar,,,eee\\"}"}'))
'{"foo": "bar,,,eee"}'
```

View File

@ -0,0 +1,10 @@
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"]

View File

@ -1,5 +0,0 @@
from .__about__ import __name__, __version__
def cli():
print(f"Running {__name__} version {__version__} from __main__.py")

View File

@ -12,9 +12,6 @@ classifiers = [
"Operating System :: OS Independent",
]
[project.scripts]
json-unescape = "json_unescape.__main__:cli"
[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"