summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patternutils/utils.py8
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]: