Boomi - Merge two JSONs

846 Views Asked by At

I have two inbound JSON data sets that I need to combine/merge in Boomi

Inbound DataSet1

{
    "Id": 1,
    "Program": [
        {
            "ProgramId": "A",
            "ProgramName": "ProgramA"
        },
        {
            "ProgramId": "B",
            "ProgramName": "ProgramB"
        }
    ]
}

and

Inbound DataSet2

{
    "Id": 1,
    "Course": [
        {
            "CourseId": "C1",
            "CourseName": "Course 1"
        },
        {
            "CourseId": "C2",
            "CourseName": "Course 2"
        }
    ]
}

Want to Combine them to the following:

{
    "Id": 1,
    "Program": [
        {
            "ProgramId": "A",
            "ProgramName": "ProgramA"
        },
        {
            "ProgramId": "B",
            "ProgramName": "ProgramB"
        }
    ],
    "Course": [
        {
            "CourseId": "C1",
            "CourseName": "Course 1"
        },
        {
            "CourseId": "C2",
            "CourseName": "Course 2"
        }
    ]
}

I defined a JSON profile with the final expected output which has Program and Course in it - however, in Data Processing when I am trying to do a Combine JSON, I am unable to choose either elements or keys to merge the documents on.

2

There are 2 best solutions below

0
Mayukh Chakravartti On BEST ANSWER

I took Kris's advise and did the following:

  • Added to Cache
  • Then combined it in a map for the unique Id
  • So now we have individual documents where its combined, but each document is separate, we need to combine them
  • In order to do so, I added a message step where i added the following: '{"Data":['{1}']}' where {1} is the current data
  • Now each document is inside the array
  • Next I used Data process to combine the documents with the common array object

See the final process in the link below. Reach out if you have questions.

Boomi Process

0
Kris Khairallah On

The approach necessitates the creation of three data profiles: one for each dataset and one for the combined format.

You load dataset2 into a document cache (make sure you have "Enforce one index entry per document" selected and that you have a document key), then you get the dataset1 into a Map (shape). In this Map, you do a lookup (Add cached data) to dataset2 based on the "Id". This will get you both profiles combined based on the Id.

The Map needs a target profile, which is where you put your combined format profile and map the fields from datasets 1 and 2 to the final profile.

I hope it helps..