Articles in this section

Mapper 2.0: Build a destination object array

To create a destination object array that contains multiple objects, use the JSONPath notation $,$ to define the number of objects contained in the object array.

  • $,$ would create an object array with two objects

  • $,$,$ would create an object array with three objects

  • $,$,$,$,$ would create an object array with five objects

Each object in the array is represented as a tab at the top of Mapper 2.0, so that you can build unique mappings for each object in the object array. Any fields added to the first object in an array are automatically added to all subsequent objects in the array; however, you can modify each subsequent object independently if necessary by selecting the $ tab that represents the object.

For example, consider the following source data:

{
  "source_field_1": "value_1",
  "source_field_2": "value_2",
  "source_field_3": "value_3"
}

In the above JSON, the source object has three fields, each of which needs to rearranged into the following object array format before import into the destination application:

{
  "destination_field_1": "value_1",
  "custom_fields": [
    {
      "name": "destination_field_2",
      "value": "value_2"
    },
    {
      "name": "destination_field_3",
      "value": "value_3"
    }
  ]
}

This JSON format has a custom_fields object array that contains two objects. Use the following steps to generate the above destination JSON structure from the source data using Mapper 2.0:

Destination (left column)

Source (right column)

  • Create the destination_field_1 string field in the left column (destination).

  • In the right column (source), use JSONPath notation to reference the source_field_1 field from the source data: $.source_field_1.

  • Create the custom_fields object array in the left column (destination).

  • Enter the following JSONPath notation in the right column (source): $,$. This allows you to select fields for both the first and second object in the custom_fields object array. Mapper 2.0 displays two tabs with the $ heading. The one on the left allows you to select fields for the first object in the custom_fields array, and the one on the right allows you to select fields for the second object. If your object array contains more than two objects, you can add additional root characters ($) to the custom_fields object array that would create additional tabs for you to map fields to each object.

  • Create the first object in the custom_fields array. Verify that the $ tab for the first object is selected, then create the name string field.

  • In this example, the name field for the first object is hard-coded as "destination_field_2".

objectToArray.png

Mappings for the first object in the custom_fields object array

  • Create the value string field for the first object in the custom_fields array.

  • Select source_field_2 from the source data: $.source_field_2.

  • Create the second object in the custom_fields array. Verify that the $ tab for the second object is selected, then create the name string field.

  • In this example, the name field for the second object is hard-coded as "destination_field_3".

objectToArray2.png

Mappings for the second object in the custom_fields object array

  • Create the value string field for the second object in the custom_fields array.

  • Select source_field_3 from the source data: $.source_field_3.

Was this article helpful?
2 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.