Skip to content

no-json-stringify-object-equality

Do not use JSON serialization as structural object equality.

Why

JSON text equality depends on property insertion order and serialization behavior, so semantically equal objects can compare unequal and distinct values can collapse together.

Fix

Compare an explicit domain projection structurally, or use a reviewed canonical serializer when JSON semantics are required.

Examples

Before — flagged Do not compare object serialization
src/compare.ts
const same =
JSON.stringify({ id: "1", state: "ready" }) ===
JSON.stringify({ state: "ready", id: "1" });
After — preferred Use an explicit structural comparator
src/compare.ts
const same = sameRecord(actual, expected);