Skip to main content
Skip table of contents

Array Alignment

This parameter gives you control over how items in arrays are matched for comparison.

It is used in both compare and the different types of merge. When a merge is resolved the result will contain the appropriate JSON objects.

Global Array Alignment Setting

Array items can be aligned currently in three ways:

  • Orderless (default)- Alignment will be done by a heuristic algorithm which assesses how similar items are rather than using their order in the array. Items which are most similar are aligned first. The algorithm favours matches based on data that uniquely identifies items over data that is common across items. Setting wordByWord to true can result in phrases matching each other even though they have little in common. This is by design.

  • Type with Value Priority - Alignment will be by equality first (same type and value), then by type. Items of different type will never align. Note that item position is still a factor, particularly where items have the same type.

  • Position Priority - Alignment will be purely by item position in the array.

Let's look at an example comparing the following arrays:

Input A

Input B

[ 116, 943, 234, 38793 ]

[ 200, "ABC", "DEF", 234, 38793 ]

Array Alignment by Type with Value Priority would result in the following comparisons and delta representation

Delta
JS
			  [
                {
                   	"dx_delta": {
                        "B": 200
                    }
                },
                {
                    "dx_delta": {
                        "A": 116
                    }
                },
                {
                    "dx_delta": {
                        "B": "ABC"
                    }
                },
                {
                    "dx_delta": {
                        "B": "DEF"
                    }
                },
                {
                    "dx_delta": {
                        "A": 943
                    }
                },
                234,
                38793
            ]

Array Alignment by Position would result in the following comparisons and delta representation

Delta
JS
			[
                {
                    "dx_delta": {
                        "A": 116,
                        "B": 200
                    }
                },
                {
                    "dx_delta": {
                        "A": 943,
                        "B": "ABC"
                    }
                },
                {
                    "dx_delta": {
                        "A": 234,
                        "B": "DEF"
                    }
                },
                {
                    "dx_delta": {
                        "A": 38793,
                        "B": 234
                    }
                },
                {
                    "dx_delta": {
                        "B": 38793
                    }
                }
            ]

In the following example, Array Alignment by Orderless would generate a delta without any changes. Note "dx_data_sets": "A=B"

Input A

Input B

["ABC", "DEF", 234, 200, 38793]

[200, "ABC", "DEF", 234, 38793]

Response
JS
{
    "dx_deltaJSON": {
        "dx_data_sets": "A=B",
        "dx_deltaJSON_type": "diff",
        "dx_deltaJSON_metadata": {
            "operation": {
                "type": "compare",
                "input-format": "multi_part",
                "output-format": "JSON"
            },
            "parameters": {
                "arrayAlignment": "orderless",
                "wordByWord": true
            }
        },
        "dx_deltaJSON_delta": [
            200,
            "ABC",
            "DEF",
            234,
            38793
        ]
    }
}

Array Alignment Setting using DxConfig

Different array alignment settings can be applied to different array by adding a 'arrayAligment' JSON object to the parameter dxConfig with a value containing an array of configuration instructions. An array is identified by a JSON Path. For example,

Input
CODE
{
    "columns": [
        "Name", "Age", "Completed Course"
    ],
    "data": [
        ["Amy", 18, false ],
        ["Beth", 50, true ]
    ]
}
DxConfig object
CODE
"dxConfig": [
  {
    "arrayAlignment": {
    "/columns": "orderess",
    "/data": "positionPriority"
    }
  }
]
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.