Я создаю ассоциативный массив, который хочу использовать для создания объекта JSON, но у меня проблема с дублирующимися ключами с разными значениями. Я хочу, чтобы ключи были дублированы, а значения объединены. Я проверил онлайн, но все решения ссылаются на 2 разных массива, а не на один и тот же массив.
Объект JSON:
{
"trailervideos": [
{
"category": "Video Games",
"videos": {
"description": "Trailer of the game Dark Souls II",
"title": "Dark Souls 2 Announcement Trailer"
}
},
{
"category": "Video Games",
"videos": {
"description": "Trailer of the DLC Scholar of the First Sin for the game Dark Souls II",
"title": "Dark Souls II Scholar of the First Sin - Forlorn Hope Trailer"
}
},
{
"category": "Video Games",
"videos": {
"description": "Trailer of the DLC Ashes of Ariendel for the game Dark Souls III",
"title": "Dark Souls III Ashes of Ariandel - Announcement Trailer PS4"
}
},
{
"category": "Entertainment",
"videos": {
"description": "",
"title": "intro"
}
}
]
}
То, чего я хочу добиться, - это объединить все значения повторяющихся ключей «Видеоигры», чтобы я мог создать объект JSON, например:
{"trailervideos":[{"category":"Video Games","videos":[{"description":"Trailer of the game Dark Souls II","title":"Dark Souls 2 Announcement Trailer"},{"description":"Trailer of the DLC Scholar of the First Sin for the game Dark Souls II","title":"Dark Souls II Scholar of the First Sin - Forlorn Hope Trailer"},{"description":"Trailer of the DLC Ashes of Ariendel for the game Dark Souls III","title":"Dark Souls III Ashes of Ariandel - Announcement Trailer PS4"}],{"category":"Entertainment","videos":{"description":"","title":"intro"}}]}