Skip to main content

first_difference

Function first_difference 

Source
pub fn first_difference(left: &Value, right: &Value) -> Option<String>
Expand description

Where two JSON values first differ, as an RFC 6901 pointer.

None when they are equal. The empty string — RFC 6901’s pointer to the whole document — when they differ at the root, which is the common case and the one a bare “they differ” message hides worst: an object was expected and null arrived.

§Why a comparison has a diagnostic in it

A refusal that says these two values are not the same leaves the reader holding two documents and a diff to do by eye. The gate this serves is the sink argument binding, where the two documents are the value policy checked and the value the effect will send, and the difference between them is the whole finding. Naming the path costs one walk of a value already in hand.

Deterministic: object members are visited in the same UTF-16 key order value_bytes writes them, so the pointer this reports does not depend on how a caller built the map. A member present on one side and absent on the other is reported at that member’s own path rather than at its parent’s, because “the object differs” is the answer the reader already had.