API Reference / @evolu/common / Eq / eqJsonValue

Function: eqJsonValue()

function eqJsonValue(a, b): boolean;

Defined in: packages/common/src/Eq.ts:111

Deeply compares two JsonValue values for equality.

  • Uses an iterative approach with a stack to handle large or deeply nested objects without risking stack overflow.
  • Handles circular references with a WeakMap to prevent infinite loops.
  • Unlike JSON.stringify, this function directly compares values, avoiding serialization overhead and leveraging short-circuit evaluation for faster failure on mismatched structures.

Example

const obj1: Json = { name: "Alice", hobbies: ["reading", "hiking"] };
const obj2: Json = { name: "Alice", hobbies: ["reading", "hiking"] };
console.log(eqJson(obj1, obj2)); // true

Parameters

ParameterType
aJsonValue
bJsonValue

Returns

boolean

Was this page helpful?