I’m trying to merge two data sources into one JSON, similar to how you would with SQL. I cannot figure out how to do that with the modules. The location is the mapping key.
Input JSON 1:
{
"location_details": [
{
"email": "lukas.mueller@example.com",
"first_name": "Lukas",
"last_name": "Müller",
"location": "A"
},
{
"email": "anna.schmidt@example.com",
"first_name": "Anna",
"last_name": "Schmidt",
"location": "B"
},
{
"email": "johannes.fischer@example.com",
"first_name": "Johannes",
"last_name": "Fischer",
"location": "C"
}
]
}
Input JSON 2:
{
"product_report": [
{
"product_id": 267375,
"availability ": 3,
"description": "Description Product 267375",
"location": "A"
},
{
"product_id": 45567,
"availability ": 7,
"description": "Description Product 45567",
"location": "A"
},
{
"product_id": 89075,
"availability ": 123,
"description": "Description Product 89075",
"location": "A"
},
{
"product_id": 22345,
"availability ": 45,
"description": "Description Product 22345",
"location": "B"
},
{
"product_id": 567990,
"availability ": 56,
"description": "Description Product 567990",
"location": "B"
},
{
"product_id": 332345,
"availability ": 89,
"description": "Description Product 332345",
"location": "C"
}
]
}
Expected Result:
[
{
"email": "lukas.mueller@example.com",
"first_name": "Lukas",
"last_name": "Müller",
"location": "A",
"products": [
{
"product_id": 267375,
"availability ": 3,
"description": "Description Product 267375",
"location": "A"
},
{
"product_id": 45567,
"availability ": 7,
"description": "Description Product 45567",
"location": "A"
},
{
"product_id": 89075,
"availability ": 123,
"description": "Description Product 89075",
"location": "A"
}
]
},
{
"email": "anna.schmidt@example.com",
"first_name": "Anna",
"last_name": "Schmidt",
"location": "B",
"products": [
{
"product_id": 22345,
"availability ": 45,
"description": "Description Product 22345",
"location": "B"
},
{
"product_id": 567990,
"availability ": 56,
"description": "Description Product 567990",
"location": "B"
}
]
},
{
"email": "johannes.fischer@example.com",
"first_name": "Johannes",
"last_name": "Fischer",
"location": "C",
"products": [
{
"product_id": 332345,
"availability ": 89,
"description": "Description Product 332345",
"location": "C"
}
]
}
]