Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
refactor: remove lib in ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
validcube committed Nov 20, 2023
1 parent ab32828 commit 4737415
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dist/
downloads/
eggs/
.eggs/
lib/
# lib/ # We use this
lib64/
parts/
sdist/
Expand Down
2 changes: 2 additions & 0 deletions lib/__init__.py
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
28 changes: 28 additions & 0 deletions lib/cleanup.py
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
28 changes: 28 additions & 0 deletions lib/formatter.py
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)

0 comments on commit 4737415

Please sign in to comment.