javascript — объединение двух объектов JSON, имеющих общий элемент

Объединить два объекта JSON, которые имеют общий элемент

У меня есть два канала JSON. Один содержит основную информацию о курсе, второй содержит информацию более административного характера. Вот пример того, что я имею в виду.

ПЕРВЫЙ

 {"courses": {"course":{"id":"4","title":"Using a computer","body":"36"}} ,{"course":{"id":"5","title":"Job hunting online","body":"29"}} } 

ВТОРОЙ

 {"courses": {"4": {"id":4,"name":"Online Basics","title":"Using a computer","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/10/31 00:12:39","on_planner":true} ,"5": {"id":5,"name":"Online Basics","title":"OB2 Job hunting online","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/11/24 02:14:51","on_planner":false} } } по {"courses": {"4": {"id":4,"name":"Online Basics","title":"Using a computer","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/10/31 00:12:39","on_planner":true} ,"5": {"id":5,"name":"Online Basics","title":"OB2 Job hunting online","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/11/24 02:14:51","on_planner":false} } } по {"courses": {"4": {"id":4,"name":"Online Basics","title":"Using a computer","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/10/31 00:12:39","on_planner":true} ,"5": {"id":5,"name":"Online Basics","title":"OB2 Job hunting online","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/11/24 02:14:51","on_planner":false} } } 

ЖЕЛАЕМЫЙ ВЫХОД

 {"courses": {"course":{"id":"4","title":"Using a computer","body":"36","name":"Online Basics","title":"Using a computer","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/10/31 00:12:39","on_planner":true}} } по {"courses": {"course":{"id":"4","title":"Using a computer","body":"36","name":"Online Basics","title":"Using a computer","shortname":"onlinebasics","height":640,"width":980,"html5":1,"url":"/sites/default/files/courses/onlinebasics/wrapper.html","started_on":"","bundle_only":true,"progress":false,"completed_on":"2012/10/31 00:12:39","on_planner":true}} } 

Я надеюсь, что добавление опции «требуемый вывод» облегчит понимание. Несмотря на то, что я поместил только 1 пример в нужную область вывода, я хочу, чтобы все записи, в которых совпадали идентификаторы, объединялись.

Какие-либо предложения?

Благодарю.

Понравилась статья? Поделиться с друзьями:
JavaScript & TypeScript
Adblock
detector