Repair malformed JSON (truncated, single quotes, trailing commas, LLM output artifacts) into valid JSON.