This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ dist/ | |
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
# lib/ # We use this | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
|
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,2 @@ | ||
from .cleanup import remove_empty # noqa: F401 | ||
# from .formatter import format_json # noqa: F401 |
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,28 @@ | ||
"""Recursively remove empty items from nested objects (dictionaries and lists) | ||
⚙️ Arg: | ||
data(dict): JSON data | ||
↪️ Return: | ||
str: JSON data without empty keys, list, dict, and array | ||
""" | ||
|
||
from typing import Any, Dict | ||
|
||
|
||
def remove_empty(data: Dict[Any, Any]) -> Dict[Any, Any]: | ||
"""Recursively remove empty items from nested objects (dictionaries and lists) | ||
⚙️ Arg: | ||
data(dict): JSON data | ||
↪️ Return: | ||
str: JSON data without empty keys, list, dict, and array | ||
""" | ||
|
||
if isinstance(data, dict): | ||
return {k: remove_empty(v) for k, v in data.items() if v is not None and v != "" and remove_empty(v) != {}} | ||
elif isinstance(data, list): | ||
return [remove_empty(v) for v in data if v is not None and v != "" and remove_empty(v) != []] | ||
else: | ||
return data |
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,28 @@ | ||
#"""Format JSON data to be more readable | ||
# | ||
#⚙️ Arg: | ||
# data(dict): JSON data | ||
# indent(int): Indentation level | ||
# | ||
#↪️ Return: | ||
# str: Formatted JSON data with 4 indents | ||
#""" | ||
# | ||
#import json | ||
# | ||
# | ||
#def format_json( | ||
# data: dict, | ||
# indent: int = 2, | ||
# ) -> dict: | ||
# """Format JSON data to be more readable | ||
# | ||
# ⚙️ Arg: | ||
# data(dict): JSON data | ||
# indent(int): Indentation level | ||
# | ||
# ↪️ Return: | ||
# str: Formatted JSON data with specified indentation | ||
# """ | ||
# | ||
# return json.dumps(data, indent=indent, ensure_ascii=False) |