I Have two objects with different structure, trying to merge this two objects with matched data based on a key value, and make a new object with complete data from object1 and object2.
my Object1
{
"schedule":{
"onward":{
"journey":[
{
"trips":[
{
"origin":{
"airportCode":"AMS"
},
"destination":{
"airportCode":"BCN"
},
"FlightNumber":"KL1665"
}
]
},
{
"trips":[
{
"origin":{
"airportCode":"AMS"
},
"destination":{
"airportCode":"BCN"
},
"FlightNumber":"MF9343"
}
]
}
]
}
}
}
object 2
{
"flights":[
{
"flightNumber":"KL1665",
"price":223,
"available":10
},
{
"flightNumber":"KL112",
"price":223,
"available":10
},
{
"flightNumber":" KL112",
"price":223,
"available":10
}
]
}
i Would like to merge "price" and "available" to object which matches with "flightNumber" and create a new object with all data.
I have tried to use loadash and underscore but couldnt figure it. Help would be great, Thank in Advance.
{"schedules": {"onwardSchedules": {"trips": [{"flights": [{"origin": {"airportCode": "AMS"}, "destination": {"airportCode": "BCN"}, "marketingFlightNumber": "KL1665","price":223, "available": 10 }] }, {"flights": [{ "origin": { "airportCode": "AMS"}, "destination": {"airportCode": "BCN" } , "marketingFlightNumber": "MF9343" }] }] } } }