Build JSON with nested and unbounded objects

JSON is a language-independent data format commonly used for transmitting data in web applications. It is integral to many modern integration patterns and can be used extensively to manipulate data in Boomi. Please refer to Boomi’s documentation on JSON profiles to learn more.

Often UConn data has a natural complexity that requires well-formed but flexible data structures. The complexity usually comes in the form of combining related data in a well-designed format that allows downstream systems to consume it in a way that meets specific business requirements. The example below shows how to combine a list of UConn campuses with the list of buildings that are on each campus. The same logic can be applied to any of the one to many relationships that naturally occur in our data ecosystem (e.g., one employee with multiple jobs, one college with multiple departments, etc.).

This article is intended for individuals who have a Boomi Associate Integration Developer Certification. If you do not know how to complete an action like “add a message shape,” please complete the recommended trainings.

 Instructions

We start with two data sets. The first is a list of UConn campuses. The second is the details of all UConn buildings.

The goal is to build a JSON object that provides information about the campus including a BUILDINGS array that contains information about each building located on that campus. A well-formed UConn Campus JSON object populated with data for the Hartford Regional Campus is shown here.

 

The process of converting the two flat files to the desired JSON object looks like this:

  1. Configure the Start Shape with the No Data option and click Ok.

  2. Connect a Branch shape with 2 branches.

  3. The next steps are dependent on your particular use case. The first branch gets the data for the many object in the target one-to-many JSON structure. The second branch gets the data for the one object. In this example, the CSV file of buildings is read from an SFTP server in the first branch, and the CSV file of campuses is read in the second.

  4. The flat file profile for the buildings looks like this:

  5. The flat file profile for the campus looks like this:

  6. Create the UConn Building JSON Profile.

     

  7. Add a Map shape to the top branch. Map the buildings into a simple JSON structure that contains a Root element with a child object. The child object should be made up of simple elements with a one-to-one mapping of the building flat file profile.

  8. Connect an Add to Cache shape to the Map shape. Create a document cache that uses the UConn Building JSON Profile and set the index to the CAMPUS_ID element. Be sure to uncheck “Enforce one index entry per document” because there are many buildings with a common CAMPUS_ID.

  9. The first branch is now complete.

  10. Create the UConn Campus JSON Profile as shown here. The Array in the buildings element is repeating. This allows the JSON to have a flexible number of buildings, since each campus has a different number of buildings.

  11. Add a Map shape on the second branch and select the UConn Campuses flat file profile as the source. Click the down-arrow next to Elements and select Add Cached Data.

  12. Select the UConn Building data cache created in step 8 and set Cache Index to campusId. Set the CAMPUS_ID key to CAMPUS_ID as shown here:

  13. This adds the elements of the Building cache to the source. Now map each element to its logical equal in the UConn Campus JSON Profile target.

  14. Add a Stop shape.

Time to Test.

How to Test

  1. Click Test in the upper right corner of the process pallet.

  2. Pick the Test Atom Cloud (TAC) available in your sub-account and click OK. This example shows the UConn Test Atom Cloud for the Main UConn account.

     

  3. The process should execute in Test mode. Once a step is completed, a green halo will appear. You will see a success message when the process is done. Click on the Stop shape, and in Test Results, go to Shape Source Data and select one of the documents.

  4. You will see the JSON with information about the campus and a BUILDINGS array that contains the many buildings for that campus.

 Related articles