diff options
| author | Dennis Fink | 2020-12-12 15:42:09 +0100 |
|---|---|---|
| committer | Dennis Fink | 2020-12-12 15:42:09 +0100 |
| commit | 88057fc82b7fcc5148526eb3685f3ee0e785740e (patch) | |
| tree | 07213278a4a8534b57affba6f2f7164853b4c9fb | |
| parent | e2726f2fca079516996c5ca65f4e9cc2e97c6595 (diff) | |
| download | patternutils-88057fc82b7fcc5148526eb3685f3ee0e785740e.tar.gz patternutils-88057fc82b7fcc5148526eb3685f3ee0e785740e.zip | |
Add json_loads to utils
| -rw-r--r-- | patternutils/utils.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/patternutils/utils.py b/patternutils/utils.py index 17e7909..5a33127 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -38,6 +38,14 @@ def json_dumps(data: Any, human_readable: bool = False) -> str: return json.dumps(data, **config) +def json_loads(data: Any) -> Any: + try: + return json.loads(data) + except json.JSONDecodeError: + click.secho("JSON not valid!", fg="red", err=True) + raise SystemExit + + def walk( directory: str, recursive: bool = False, match_directories: bool = False ) -> Generator[os.DirEntry[Any], None, None]: |
