I want to combine two JSON datasets in a flow

I’m trying to amalgamate two JSON data sets in a flow. I have outlined below an example of what I need to achieve.

Data set 1 (clients)

[
{
“Id”: “ABCD”,
“Department”: “C1000”,
“status”: “Active”
},
{
“Id”: “BCDE”,
“Department”: “C2000”,
“status”: “Active”
},
{
“Id”: “CDEF”,
“Department”: “C4000”,
“status”: “Active”
}
]

Data set 2 (Jobs)

[
{
“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “12345”
},
{
“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “14765”

},
{
“jobclient”: “ABCD”,
“jobdept”: “C6000”,
“key”: “1275”
},

{

“jobclient”: “CDEF”,
“jobdept”: “C6000”,
“key”: “2345”

},

{

“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “182245”

}

]

Required output would be a ….

[

{

“Id”: “ABCD”,
“Department”: “C1000”,
“status”: “Active”,
“jobclient”: “ABCD”,
“jobdept”: “C6000”,
“key”: “1275”

},

{

“Id”: “BCDE”,
“Department”: “C2000”,
“status”: “Active”,

“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “12345”

},

{

“Id”: “BCDE”,
“Department”: “C2000”,
“status”: “Active”,

“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “14765”

},

{

“Id”: “BCDE”,
“Department”: “C2000”,
“status”: “Active”,

“jobclient”: “BCDE”,
“jobdept”: “C6000”,
“key”: “182245”

},

{

“Id”: “CDEF”,
“Department”: “C4000”,
“status”: “Active”,
“jobclient”: “CDEF”,
“jobdept”: “C6000”,
“key”: “2345”

}

]

The output needs to run through the client dataset and create a record for each time it finds a match in the jobs dataset.

I’m sure it will require an “Evaluate” block and use the $map function but I have no idea how to write it. Can anyone help?

Hi @advectus1974

This can be done in an evaluate block and you can even use Postbot to help you generate the TypeScript code to do it!

Try this solution and adjust as needed:

jobs.map(job => {
    const matchingClient = clients.find(client => client.Id === job.jobclient);

    if (matchingClient) {
        return { ...matchingClient, ...job };
    }
    return null;  // Optional: handle case where no matching client is found
}).filter(Boolean);

I named your first json clients and second json jobs in the evaluate block to get this result:

Let me know if you run into any issues.