/** * Parse `text` as JSON, returning `defaultValue` (default: `undefined`) * when the input isn't valid JSON. * * @example * ```ts * const config = safeJsonParse(rawText, { mode: 'default' }) * ``` */ export declare function safeJsonParse(text: unknown, defaultValue?: T): T | undefined; /** * Result-flavored variant: surfaces *why* a parse failed when callers * want to log the difference between "empty input" and "malformed input". */ // eslint-disable-next-line pickier/no-unused-vars export declare function safeJsonParseResult(text: unknown): { ok: true, value: T } | { ok: false, reason: 'not-string' | 'empty' | 'malformed', error?: unknown }; /** * Stringify with cycle and bigint safety. * * `JSON.stringify` throws on circular refs (rare but real, e.g. logger * captures of an Express-style req object) and on bigint values (common * with database IDs that overflow Number). This wrapper substitutes * `[Circular]` for cycles and converts bigints to strings — same shape * downstream consumers expect from a "best-effort serialize this for * logs" call. */ export declare function safeJsonStringify(value: unknown, space?: number): string; /** * Safe JSON wrappers. * * Bare `JSON.parse(s)` throws `SyntaxError` on malformed input — * which 90% of the time is exactly what you want, except in: * * - Webhook handlers: a malformed payload should produce a 400, not crash * - Cache reads: a corrupt cache entry should miss, not throw * - Log readers: a bad line should be skipped, not stop the parser * - User-supplied config: a typo should produce a clear "X is invalid" error * * `safeJsonParse` returns `undefined` for malformed input (or a typed * default), so call sites don't need a try/catch ladder around every * untrusted input. `safeJsonParseResult` returns a discriminated union * for cases where the failure reason matters. */ export type JsonValue = | string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }