Skip to content
← escentmachine field notes

An inserted array item can look like three changes

You add one item to the beginning of an array and a comparison reports several changed values. The result can be correct. It depends on whether the comparison tracks positions, item identities or an unordered set. Those are different questions, and none can be inferred safely from every JSON document.

The rule here: zero-based positions

Before: {"steps":["build","test"]}
After:  {"steps":["lint","build","test"]}

Expected differences:
Changed $["steps"][0]: "build" → "lint"
Changed $["steps"][1]: "test" → "build"
Added   $["steps"][2]: (absent) → "test"

Run the array-insertion example →

JSON Compare checks each zero-based index. It does not label a change as a move, search for a matching id field or treat the array as a set. For an execution pipeline, order often is the data. A positional diff makes the change to each step explicit.

Objects follow a different rule

Object keys are compared by their decoded names, regardless of source order. The path uses JSON-quoted bracket notation so keys containing dots, quotes or spaces remain unambiguous. Added and removed subtrees are reported at the path where they enter or leave the document; changing a value’s type is one change at that path.

Before: {"name":"worker","count":1e3}
After:  {"count":1000,"name":"worker"}

Expected: no structural differences.

Numeric tokens are compared as exact decimal values, so 1e3 and 1000 are equivalent. Strings are compared as decoded Unicode sequences, booleans by value, and null only with null. Negative zero and zero compare equal. These rules deliberately differ from a textual diff of whitespace and spelling.

Do you actually need identity matching?

If an API defines an array as records identified by a stable key, a domain-specific comparison may be more useful. Verify that the key exists and is unique before transforming the data into a keyed object for inspection. Sorting arrays blindly can hide meaningful ordering changes or conflate duplicate items.

The tool rejects duplicate object keys in either input. It also rejects invalid JSON before producing a diff. Your source documents remain editable, and the error identifies whether the baseline or candidate failed. Large integers keep their exact numeric tokens throughout comparison.

Read and copy the same result

Every result is labeled Added, Removed or Changed; color is only a secondary cue. Copy diff exports the displayed changes as JSON together with the total count and comparison rule. At most 1,000 changes are displayed and copied, with truncation explicitly flagged. Narrow the input when you need to inspect a larger result completely.

Previous note
Next note