The string to clean and parse, which may contain JSON in various formats
If true, parsing errors will be logged to console (default: false)
The parsed object of type T, or null if cleaning/parsing fails
// Parse double-escaped JSON
const result = CleanAndParseJSON<{name: string}>('{\\"name\\": \\"test\\"}', true);
// Returns: {name: "test"}
// Parse JSON from markdown
const data = CleanAndParseJSON<{id: number}>('json\n{"id": 123}\n', false);
// Returns: {id: 123}
// Parse complex AI response with type safety
interface AIResponse {
status: string;
data: any;
}
const response = CleanAndParseJSON<AIResponse>(aiOutput, true);
// Returns typed object or null
Combines CleanJSON and SafeJSONParse to clean, extract, and parse JSON in one operation. This is a convenience function that first cleans the input string using CleanJSON to handle various formats (double-escaped, markdown blocks, etc.), then safely parses the result.