Datadiff can match objects in an array by a caller-selected field such as id. With --key id, moving an object to a different position is not, by itself, reported as a change. That makes keyed matching a practical fit for record collections whose entries have stable identities. The project documents this behavior; it does not provide a maintainer statement confirming that avoiding tree edit distance was its original design motivation.
How datadiff matches array entries
For arrays of objects, pass a field with --key so datadiff can associate entries across the old and new documents by that field. For example, datadiff old.json new.json --key id tells it to use each object’s id as the matching key. The project’s example shows differently ordered arrays producing 0 changes (0 added, 0 removed, 0 modified) under this option. Datadiff project documentation
As an Amazon Associate I earn from qualifying purchases.
This rule separates identity from position: an object with the same key can still be treated as the same record after it moves. Without an identity rule, a comparison may need to interpret structural similarities and edits to decide which entries correspond. Datadiff instead lets the caller state the correspondence rule directly.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Why use a key rather than tree edit distance?
Tree edit distance is a general way to compare trees: it defines the distance as the minimum-cost sequence of node edits needed to transform one tree into another. The result depends on the edit-cost model and the mapping chosen under that model. It is useful for general tree transformation and similarity problems, but it solves a broader matching problem than pairing records by a known identifier. University of Salzburg Tree Edit Distance reference
#1 Best Overall
For a collection such as users or products, a stable identifier often already supplies the correspondence a diff needs. A caller-selected key therefore makes the match explicit and predictable, while treating array order as incidental. This is a practical rationale inferred from datadiff’s documented behavior, not a quoted explanation of the maintainers’ intent.
Which approach fits the data?
| Question | Datadiff keyed matching | Tree edit distance |
|---|---|---|
| How are entries matched? | By a caller-supplied field, such as id. Datadiff project documentation |
By a mapping selected through tree structure and edit costs. University of Salzburg reference |
| What does reordering mean? | With keyed matching, a pure reorder is not reported as a data change. Datadiff project documentation | There is no universal answer independent of the tree representation and cost model; the method seeks a low-cost edit mapping. University of Salzburg reference |
| Best-aligned problem | Comparing records whose identity is known and stable across versions. | General tree transformation or similarity when correspondences are not given by an explicit record key. |
| What determines correspondence? | The selected key makes the rule visible in the command. | The algorithm’s mapping under its edit model determines the correspondence. |
Choose keyed matching when the key genuinely identifies the same entity across versions and array position is not meaningful. If order itself carries meaning—for example, a ranked sequence—then “reordering is not a change” may not express the comparison you want. The documented keyed behavior should not be mistaken for a universal claim about array semantics.
Rank #2
- color: White
- INTRODUCTION TO ALGORITHMS, FOURTH EDITION
What the project’s performance comparison does—and does not—show
The datadiff project comparison reports 0.07 seconds for datadiff 0.2.0 on a 1,000-object, 112 KB JSON input; it says Graphtage 0.3.1 did not finish that case within ten minutes. These are project-reported figures, and the published material surfaced here does not establish independent testing or a general result for other inputs and implementations. Datadiff project documentation
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11That comparison can illustrate one reported run, but it cannot prove that tree edit distance is always too slow or unsuitable. Tree shape, cost model, implementation, and task all matter. The Salzburg reference describes RTED strategy computation as quadratic in time and space and characterizes the general algorithm as at least quadratic; that algorithmic description is not a direct benchmark of datadiff. University of Salzburg Tree Edit Distance reference
Rank #3
Output and JSON Patch implications
Datadiff documents text, native JSON, and JSON Patch output modes. In JSON Patch mode, key-matched paths are resolved to numeric positions using the old document. Additions use the RFC 6902 append path, and removals from arrays are ordered by descending index so earlier removals do not shift the remaining positions. Datadiff project documentation
There are two path-related caveats. The documentation says object keys containing ., [, or ] cannot be patched because its path representation cannot express them. Also, the separate patch subcommand consumes datadiff’s native JSON format, not RFC 6902 JSON Patch.
Command shape and documented scope
The documented command pattern is datadiff <old> <new> [--key <field>] [--format <json|yaml|csv|toml|xml>] [--show-unchanged] [--no-color] [--output <text|json|patch>]. Datadiff says it autodetects formats from file extensions and accepts --format as an override. Its stated structured-data formats are JSON, YAML, CSV, TOML, and XML; it also says object key order and formatting are ignored. Datadiff project documentation
The same identity idea appears in the project’s CSV example: rows are matched by the id column, so an edited price is attributed to that record and additions or removals are identified by row key. The matching key is therefore not limited to JSON arrays, though the precise data representation differs by format.
Best Value
- Binding: paperback
- Language: english
- It ensures you get the best usage for a longer period
Key cases the documentation does not settle
The surfaced documentation does not establish how datadiff handles missing or duplicate key values. Do not assume a fallback matching rule or a particular error behavior from the documented pure-reorder example; those cases require implementation-specific confirmation.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




