[
{
"name": "spotify",
"data": [
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW1",
"parent": {
"position": 2,
"service": "spotify"
}
}
]
},
{
"name": "yandex",
"data": [
{
"name": "А если это любовь?",
"author": "HammAli & Navai_1",
"parent": {
"position": 34,
"service": "yandex"
}
},
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW_2",
"parent": {
"position": 29,
"service": "yandex"
}
}
]
},
{
"name": "apple",
"data": [
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW_3",
"parent": {
"position": 11,
"service": "apple"
}
},
{
"name": "А если это любовь?",
"author": "HammAli & Navai_2",
"parent": {
"position": 47,
"service": "apple"
}
}
]
}
]
[
[
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW",
"parent": {
"position": 2,
"service": "spotify"
}
},
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW",
"parent": {
"position": 29,
"service": "yandex"
}
},
{
"name": "Снова я напиваюсь",
"author": "SLAVA MARLOW",
"parent": {
"position": 11,
"service": "apple"
}
}
],
[
{
"name": "А если это любовь?",
"author": "HammAli & Navai",
"parent": {
"position": 47,
"service": "apple"
}
},
{
"name": "А если это любовь?",
"author": "HammAli & Navai",
"parent": {
"position": 34,
"service": "yandex"
}
}
]
]
import json
f = open('join.json')
data_array = json.load(f)
i = 0
massiv = []
for i in range(len(data_array)):
j = 0
dlina = len(data_array[i])
data_enter = data_array[i]
for j in range(len(data_enter)):
try:
data_enter = data_enter['data'][j]
massiv.append(data_enter['author'])
j+=1
except:
break
i+=1
print(massiv)
f.close()
Входные данные
Данные, которые должны получится на выходе
import json
with open('join.json') as f:
original_data = json.load(f)
new_data = []
for element in original_data:
for data in element['data']:
name = data['name']
found = False
for new_element in new_data:
for new_list in new_data:
if new_list[0]['name'] == name:
new_list.append(data)
found = True
break
if found:
break
if not found:
new_data.append([data])
print(new_data)