/** * JSON Parsing Utilities * * Safe JSON parsing with context for better error messages. * * @module util/json */ /** * Error thrown when JSON parsing fails */ export declare class JsonParseError extends Error { readonly source: string; readonly originalError: Error; readonly rawContent?: string | undefined; constructor(message: string, source: string, originalError: Error, rawContent?: string | undefined); } /** * Options for JSON parsing */ export interface ParseJsonOptions { /** Include the raw content in error (default: false, could be large) */ includeRawInError?: boolean; /** Maximum length of raw content to include in error */ maxRawLength?: number; /** Reviver function for JSON.parse */ reviver?: (key: string, value: unknown) => unknown; } /** * Parse JSON with context for better error messages * * @param raw - The raw JSON string to parse * @param source - A label describing where this JSON came from (e.g., "semgrep output", "npm audit") * @param options - Parsing options * @returns The parsed JSON value * @throws JsonParseError if parsing fails * * @example * ```typescript * const data = parseJson(stdout, "gosec output"); * const config = parseJson(fileContent, `config file: ${filePath}`); * ``` */ export declare function parseJson(raw: string, source: string, options?: ParseJsonOptions): T; /** * Try to parse JSON, returning undefined on failure */ export declare function tryParseJson(raw: string, source: string, options?: ParseJsonOptions): T | undefined; /** * Parse JSON with a default value on failure */ export declare function parseJsonOrDefault(raw: string, source: string, defaultValue: T, options?: ParseJsonOptions): T; /** * Validate that a value is valid JSON (for pre-checks) */ export declare function isValidJson(raw: string): boolean; /** * Safely stringify JSON with error handling */ export declare function safeStringify(value: unknown, options?: { pretty?: boolean; replacer?: (key: string, value: unknown) => unknown; }): string; //# sourceMappingURL=json.d.ts.map