Compare Nested Arrays Online
Paste two nested or multi-dimensional arrays. See structural differences at every depth — recursively.
🔒 100% private — runs entirely in your browseror try sample data
Paste two nested or multi-dimensional arrays. See structural differences at every depth — recursively.
🔒 100% private — runs entirely in your browseror try sample data
Nested array comparison is the process of recursively diffing multi-dimensional arrays — arrays that contain other arrays, objects, or a mix of both. Unlike flat array comparison, which only checks top-level elements, nested comparison must walk every level of depth to detect differences in inner structures. This tool handles that complexity automatically, producing a clear visual diff that shows changes at any depth.
Multi-dimensional data structures are everywhere in software. Spreadsheet data is naturally a 2D array (rows of columns). Game boards, pixel grids, and mathematical matrices are all nested arrays. Configuration files often contain arrays of groups, where each group contains arrays of settings. Tree structures serialized as JSON use nested arrays to represent parent-child relationships. When any of these change, you need a comparison tool that understands the hierarchical structure rather than treating inner arrays as opaque blobs.
Paste your nested arrays as JSON. The tool supports nesting up to 10 levels deep and handles mixed types within nested structures (arrays containing objects containing arrays, etc.). Each level of difference is shown with path-based context, so you can see exactly where in the structure a change occurred. Everything runs in your browser — no data is transmitted to any server.
function deepEqual(a, b) { if (a === b) return true; if (typeof a !== typeof b) return false; if (a === null || b === null) return false; if (Array.isArray(a) && Array.isArray(b)) { if (a.length !== b.length) return false; return a.every((val, i) => deepEqual(val, b[i])); } if (typeof a === "object") { const keysA = Object.keys(a); const keysB = Object.keys(b); if (keysA.length !== keysB.length) return false; return keysA.every(key => deepEqual(a[key], b[key])); } return false;
} const grid1 = [[1, 2, 3], [4, 5, 6]];
const grid2 = [[1, 2, 3], [4, 55, 6]]; console.log(deepEqual(grid1, grid2)); // false // Finding which cells differ
grid1.forEach((row, r) => { row.forEach((cell, c) => { if (!deepEqual(cell, grid2[r]?.[c])) { console.log(`Diff at [${r}][${c}]: ${cell} -> ${grid2[r][c]}`); } });
});
// Diff at [1][1]: 5 -> 55This recursive approach handles arrays, objects, and primitives. For production use, add cycle detection to avoid infinite loops on circular references.
def nested_diff(a, b, path="root"): diffs = [] if type(a) != type(b): diffs.append(f"{path}: type changed {type(a).__name__} -> {type(b).__name__}") return diffs if isinstance(a, list): for i in range(max(len(a), len(b))): if i >= len(a): diffs.append(f"{path}[{i}]: added {b[i]}") elif i >= len(b): diffs.append(f"{path}[{i}]: removed {a[i]}") else: diffs.extend(nested_diff(a[i], b[i], f"{path}[{i}]")) elif isinstance(a, dict): for key in set(list(a.keys()) + list(b.keys())): if key not in a: diffs.append(f"{path}.{key}: added {b[key]}") elif key not in b: diffs.append(f"{path}.{key}: removed {a[key]}") else: diffs.extend(nested_diff(a[key], b[key], f"{path}.{key}")) elif a != b: diffs.append(f"{path}: {a} -> {b}") return diffs matrix1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
matrix2 = [[1, 2, 3], [4, 55, 6], [7, 8, 9, 10]] for d in nested_diff(matrix1, matrix2): print(d)
# root[1][1]: 5 -> 55
# root[2][3]: added 10Path tracking is essential for nested diffs — without it, you know something changed but not where. The path string (e.g., root[1][1]) tells you exactly which element in the hierarchy was modified.
import java.util.Arrays;
import java.util.Objects; public class NestedArrayDiff { // Java's built-in deep comparison public static void main(String[] args) { int[][] matrix1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int[][] matrix2 = {{1, 2, 3}, {4, 55, 6}, {7, 8, 9}}; // Built-in deep comparison boolean equal = Arrays.deepEquals(matrix1, matrix2); System.out.println("Equal: " + equal); // false // Find specific differences for (int r = 0; r < matrix1.length; r++) { int maxCol = Math.max(matrix1[r].length, r < matrix2.length ? matrix2[r].length : 0); for (int c = 0; c < maxCol; c++) { int val1 = c < matrix1[r].length ? matrix1[r][c] : -1; int val2 = r < matrix2.length && c < matrix2[r].length ? matrix2[r][c] : -1; if (val1 != val2) { System.out.printf("Diff at [%d][%d]: %d -> %d%n", r, c, val1, val2); } } } // Diff at [1][1]: 5 -> 55 } // For Object arrays, use Objects.deepEquals static boolean compareNested(Object[] a, Object[] b) { return Objects.deepEquals(a, b); }
}Java's Arrays.deepEquals() recursively compares nested arrays of any depth. For non-array objects within the structure, it falls back to equals(), so ensure your objects implement equals() and hashCode() properly.
If a nested structure contains a reference back to a parent element (a circular reference), any recursive comparison will loop forever and eventually crash with a stack overflow. JSON does not support circular references (serialization will fail), so if you are working with in-memory objects, break cycles before comparing. This tool works with JSON data which is inherently acyclic.
A "ragged" array has inner arrays of different lengths, like [[1, 2], [3, 4, 5], [6]]. When comparing two ragged arrays, extra or missing elements in inner arrays can cause cascading positional mismatches. If your inner arrays have different lengths, consider enabling "Ignore array order" or normalizing them to consistent lengths before comparing.
When a value at a position changes from a primitive to a nested array (e.g., 5 becomes [5, 6]), the diff shows the old value as removed and the new structure as added, rather than showing a "modification." This is intentional — a type change from scalar to array is a structural transformation, not an edit, and is best understood as a replacement.
Paste both nested arrays as JSON into the two panels and click Compare. The tool recursively walks every level of nesting, comparing inner arrays, objects, and primitive values. Differences at any depth are shown with color coding — red for removals, green for additions, orange for modifications.
The tool supports nesting up to 10 levels deep. This covers virtually all practical data structures, including deeply nested configuration files, recursive tree data, multi-dimensional matrices, and complex API response payloads.
Yes. A 2D array is simply an array of arrays. Paste your matrices as JSON — for example, [[1, 2], [3, 4]] — and the tool compares each row element by element, then each cell within rows. Row-level additions, removals, and cell-level changes are all detected.
Yes. This tool runs entirely in your browser using client-side JavaScript. No data is sent to any server. Your nested structures, configuration data, and multi-dimensional arrays remain completely private.
When one position contains a nested array and the corresponding position in the other array contains a primitive (or a different structure), the tool shows this as a structural change. The old value is marked as removed and the new value as added, making it clear that the data shape changed, not just the content.
Yes. The tool handles heterogeneous nested structures. An array like [[1, 2], {"key": "value"}, "string"] is compared element by element, with each element diffed according to its type — arrays are compared recursively, objects are compared by key-value pairs, and primitives are compared directly.