Hello help me please friends! I have:
[
{
"id": 1,
"name": "Zach But",
"article": "Article_1"
},
{
"id": 2,
"name": "Zach But",
"article": "Article_2"
},
{
"id": 3,
"name": "Ann Spring",
"article": "Article_3"
},
{
"id": 4,
"name": "Ann Spring",
"articles": "Article_4"
}
]
Need result:
[
{
"id": 1,
"name": "Zach But",
"article": [
"Article_1",
"Article_2"
]
},
{
"id": 2,
"name": "Ann Spring",
"article": [
"Article_3",
"Article_4"
]
}
]
That is, I have duplicate data on authors who have different articles, and I need to add these articles to each of the authors so that the authors do not repeat themselves. Please tell me how to do it right.
f = open('authors_test.json')
data = json.load(f)
for i in range(0, len(data)):
if data[i]['name'] == data[i-1]['name']:
# dont know
I can load json from a file and compare objects by author name, but I don’t know how to further implement what I need so that I end up with one object with each author, which has an array of articles