Skip to content

no-json-stringify-error

Avoid generic JSON serialization that can omit native Error details.

Why

Native Error details are non-enumerable, so generic JSON serialization discards diagnostic information.

Fix

Serialize explicit error fields or use an error-aware serializer.

Examples

Before — flagged Do not stringify an Error object
src/report.ts
try {
f();
} catch (err) {
JSON.stringify({ error: err });
}
After — preferred Narrow an unknown catch value before selecting fields
src/report.ts
try {
f();
} catch (err) {
JSON.stringify({ error: err instanceof Error ? err.message : String(err) });
}