My function
def string_info(json_info, string):
if type(json_info) == dict:
for key in json_info.keys():
other = string_info(json_info[key], "")
string += f"\n{key}:\t{other}"
elif type(json_info) == list:
for index in range(0, len(json_info)):
string += f"{json_info[index]} "
else:
string += f"{json_info}"
return string
Sample JSON
"statistics": {
"level": {
"current": 100,
"progress": 52
},
"pp": 5934,
"pp_rank": 15496,
"ranked_score": 15283968302,
"hit_accuracy": 98.3355,
"play_count": 76169,
"play_time": 3855235,
"total_score": 79160699555,
"total_hits": 13126452,
"maximum_combo": 2104,
"replays_watched_by_others": 24,
"is_ranked": true,
"grade_counts": {
"ss": 51,
"ssh": 22,
"s": 1202,
"sh": 224,
"a": 1272
},
"rank": {
"global": 15496,
"country": 2553
}
}
My Output
level:
current: 100
progress: 52
pp: 5934
pp_rank: 15496
ranked_score: 15283968302
hit_accuracy: 98.3355
play_count: 76169
play_time: 3855235
total_score: 79160699555
total_hits: 13126452
maximum_combo: 2104
replays_watched_by_others: 24
is_ranked: True
grade_counts:
ss: 51
ssh: 22
s: 1202
sh: 224
a: 1272
rank:
global: 15496
country: 2553
It seems like the tabs are not the same size for every line and I was expecting an output more along the lines of
level:
current: 100
progress: 52
pp: 5934
pp_rank: 15496
ranked_score: 15283968302
hit_accuracy: 98.3355
play_count: 76169
play_time: 3855235
total_score: 79160699555
total_hits: 13126452
maximum_combo: 2104
replays_watched_by_others: 24
is_ranked: True
grade_counts:
ss: 51
ssh: 22
s: 1202
sh: 224
a: 1272
rank:
global: 15496
country: 2553
I'm pretty new to programming with python, and I was wondering what mistake I have made to have inconsistent tabs and having the spacing not as I expected in the output. Thanks for any help.
(Also, the if statement for the if is for other types of data I might be getting from a JSON)