From 7fc7ab2a08e2c5af1a0ef789ed677301a079c57c Mon Sep 17 00:00:00 2001 From: Steve Zehui Ji Date: Tue, 14 Jul 2020 22:06:38 +1000 Subject: [PATCH 1/2] Update create_json_from_dict.py Correct the mistake which uses json.dumps() to convert dict to json object. --- python-for-beginners/17 - JSON/create_json_from_dict.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-for-beginners/17 - JSON/create_json_from_dict.py b/python-for-beginners/17 - JSON/create_json_from_dict.py index 9f5d25b7..7484b559 100644 --- a/python-for-beginners/17 - JSON/create_json_from_dict.py +++ b/python-for-beginners/17 - JSON/create_json_from_dict.py @@ -6,7 +6,7 @@ person_dict['City']='Seattle' # Convert dictionary to JSON object -person_json = json.dumps(person_dict) +person_json = json.loads(person_dict) # Print JSON object -print(person_json) +print(json.dumps(person_json)) From f6599b374253f76069238f7ca2c1d5882cafb3bd Mon Sep 17 00:00:00 2001 From: Steve Zehui Ji Date: Tue, 14 Jul 2020 22:13:56 +1000 Subject: [PATCH 2/2] Correct misuse of json.dumps() I correct all json.dumps() to json.loads() where the comment is saying "Convert dictionary to JSON object". Because usually json.dumps() is used to converting JSON objects to Python String objects. --- python-for-beginners/17 - JSON/create_json_with_list.py | 4 ++-- .../17 - JSON/create_json_with_nested_dict.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python-for-beginners/17 - JSON/create_json_with_list.py b/python-for-beginners/17 - JSON/create_json_with_list.py index 1a4cdb02..b9c62479 100644 --- a/python-for-beginners/17 - JSON/create_json_with_list.py +++ b/python-for-beginners/17 - JSON/create_json_with_list.py @@ -12,7 +12,7 @@ person_dict['languages']= languages_list # Convert dictionary to JSON object -person_json = json.dumps(person_dict) +person_json = json.loads(person_dict) # Print JSON object -print(person_json) \ No newline at end of file +print(json.dumps(person_json)) \ No newline at end of file diff --git a/python-for-beginners/17 - JSON/create_json_with_nested_dict.py b/python-for-beginners/17 - JSON/create_json_with_nested_dict.py index 8403354c..0a8e1681 100644 --- a/python-for-beginners/17 - JSON/create_json_with_nested_dict.py +++ b/python-for-beginners/17 - JSON/create_json_with_nested_dict.py @@ -10,7 +10,7 @@ staff_dict ={} staff_dict['Program Manager']=person_dict # Convert dictionary to JSON object -staff_json = json.dumps(staff_dict) +staff_json = json.loads(staff_dict) # Print JSON object -print(staff_json) \ No newline at end of file +print(json.dumps(staff_json)) \ No newline at end of file