Eric Park | 6d1ea8a | 2019-04-14 00:02:32 +0800 | [diff] [blame^] | 1 | import json |
| 2 | |
| 3 | # Previous/new JSON file here |
| 4 | old_file_name = "profile.json" |
| 5 | new_file_name = "profile_new.json" |
| 6 | |
| 7 | # Read previous JSON |
| 8 | with open(old_file_name, "r") as read_json: |
| 9 | old_data = json.load(read_json) |
| 10 | print("JSON loaded successfully. Beginning conversion...") |
| 11 | |
| 12 | # Initialize new dictionary |
| 13 | user_list = [] |
| 14 | |
| 15 | # Conversion |
| 16 | index = 0 |
| 17 | for i in old_data["Name"]: |
| 18 | user = {} |
| 19 | user["name"] = i |
| 20 | user["email"] = old_data["Email"][index][7:] |
| 21 | user["avatar"] = old_data["Avatar"][index] |
| 22 | user["description"] = old_data["Description"][index] |
| 23 | user["github"] = old_data["Github"][index] |
| 24 | user["xda"] = old_data["XDA"][index] |
| 25 | user["facebook"] = old_data["Facebook"][index] |
| 26 | user["twitter"] = old_data["Twitter"][index] |
| 27 | user["instagram"] = old_data["Instagram"][index] |
| 28 | user["googleplus"] = old_data["GooglePlus"][index] |
| 29 | user_list.append(user) |
| 30 | index += 1 |
| 31 | |
| 32 | # Verify each user |
| 33 | for i in user_list: |
| 34 | print(i) |
| 35 | |
| 36 | # Write new JSON |
| 37 | with open(new_file_name, "w") as write_json: |
| 38 | json.dump(user_list, write_json, indent=4) |