1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| """
0 id
1 parent_id
2 name
3 birthday
4 deathday
5 conjoint
6 generation
"""
json_0 = ""
for p in text_7:
parent = p[1]
if p[0] == 0: # debex
json_0 ='{ "id": '+str(p[0])+', "name": "'+p[2]+'","birthday": '+p[3]+',"generation": '+str(p[6])+''
else:
if p[1] == previous_id: # actuel est enfant du précédent
json_0 += ',"children": [ { "id": '+str(p[0])+', "name": "'+str(p[2])+'","birthday": '+p[3]+',"generation": '+str(p[6])+''
previous_is_children = True
elif p[1] == previous_parent: # actuel est frère/soeur du précédent
json_0 += '},{ "id": ' + str(p[0]) + ', "name": "' + p[2] + '","birthday": ' +p[3]+',"generation": '+str(p[6])+''
previous_is_children = True
else:
gen = '}'
for a in range(previous_generation - p[6]):
gen += ']},'
json_0 += gen+'{ "id": ' + str(p[0]) + ', "name": "' + p[2] + '","birthday": ' +p[3]+',"generation": '+str(p[6])+''
previous_is_children = False
previous_id = p[0]
previous_parent = p[1]
previous_generation = p[6]
json_0 += '}'
gen = ''
for a in range(previous_generation):
gen += ']},'
json_0 += gen
json_0 = json_0[:-1]
print(json_0) |
Partager