Array Comparison Methods
JSON arrays can be compared in different ways depending on whether order matters, how you want insertions and deletions reported, and whether duplicate values are significant. Compare JSON offers three array comparison methods.
By Index
Each element is compared to the element at the same position in the other array.
[1, 2, 3]
[1, 3, 2]
With By Index, the second and third positions are both reported as changed because 2 became 3 and 3 became 2. This method is the strictest and works best when arrays are ordered and positional alignment is expected, such as sorted lists or fixed-size tuples.
LCS (Longest Common Subsequence)
LCS finds the longest ordered sequence of elements that appears in both arrays. Elements inside that sequence are considered unchanged, while elements outside it are reported as inserted or deleted.
[1, 2, 3, 4]
[1, 3, 4, 5]
With LCS, 1, 3, and 4 form the common subsequence, so 2 is reported as deleted and 5 as added. LCS is useful when arrays are mostly ordered but may have values inserted or removed in the middle, such as changelog entries or ordered event logs.
Unordered
Arrays are compared as sets, ignoring element order and duplicate values.
[1, 2, 2, 3]
[3, 1, 2]
With Unordered, these arrays are considered the same because they contain the same unique values. If one array contains 4 and the other does not, 4 is reported as added. This method is ideal when arrays represent collections where order does not matter, such as tag lists or permission sets.
Choosing a Method
| Use case | Recommended method |
|---|---|
| Ordered lists, tuples, sequences | By Index |
| Ordered lists with occasional insertions or deletions | LCS |
| Sets, tags, permissions, categories | Unordered |
You can change the array comparison method in the Settings panel before running a comparison.