Skip to content

Commit

Permalink
Refactor main.py to convert keys in JSON objects to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
kkdai committed Jul 11, 2024
1 parent e3874b1 commit 58453d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ async def handle_callback(request: Request):
card_obj = parse_gemini_result_to_json(result.text)
print("------------JSON---------------")
print(card_obj)
card_obj = {k.lower(): v for k, v in card_obj.items()}
print("------------lowercase---------------")
print(card_obj)

# check card_obj is json obj
if card_obj is None:
Expand Down Expand Up @@ -180,7 +183,9 @@ def load_json_string_to_object(json_str):
"""
try:
json_str = json_str.replace("'", '"')
return json.loads(json_str)
json_obj = json.loads(json_str)
json_obj = {k.lower(): v for k, v in json_obj.items()}
return json_obj
except json.JSONDecodeError as e:
print(f"Error loading JSON string: {e}")
return None
Expand Down

0 comments on commit 58453d2

Please sign in to comment.