Note: Everything below from Claude Code. And I'm so thankful for this library; it's great! The weird case I'm sending is from gemini-2.5-flash-lite, which apparently loves to mess up JSON. Is regex right for this fix, as Claude Code suggests? I really don't know... Anyway thanks again.
Feature request: Handle duplicated/echoed key pattern from Gemini
Pattern Description
Gemini sometimes returns malformed JSON with an echoed key inside the value:
{"coach_notes": "coach_notes": "You showed grace under pressure."}
The key "coach_notes" appears twice - once as the actual key, and once echoed at the start of the value.
Expected valid JSON
{"coach_notes": "You showed grace under pressure."}
Current behavior
JsonRemedy returns:
{:error, "Could not repair JSON - all layers processed but validation failed"}
Suggested fix
This pattern can be detected with regex:
~r/^\{"([^"]+)":\s*"\1":\s*"((?:[^"\\]|\\.)*)"\}$/s
Where \1 back-references the first captured key name.
Context
This is a Gemini-specific bug that occurs occasionally with structured output responses. We've seen it with coach_notes but it could happen with any key.
Note: Everything below from Claude Code. And I'm so thankful for this library; it's great! The weird case I'm sending is from gemini-2.5-flash-lite, which apparently loves to mess up JSON. Is regex right for this fix, as Claude Code suggests? I really don't know... Anyway thanks again.
Feature request: Handle duplicated/echoed key pattern from Gemini
Pattern Description
Gemini sometimes returns malformed JSON with an echoed key inside the value:
{"coach_notes": "coach_notes": "You showed grace under pressure."} The key "coach_notes" appears twice - once as the actual key, and once echoed at the start of the value. Expected valid JSON {"coach_notes": "You showed grace under pressure."} Current behavior JsonRemedy returns: {:error, "Could not repair JSON - all layers processed but validation failed"} Suggested fix This pattern can be detected with regex: ~r/^\{"([^"]+)":\s*"\1":\s*"((?:[^"\\]|\\.)*)"\}$/s Where \1 back-references the first captured key name. Context This is a Gemini-specific bug that occurs occasionally with structured output responses. We've seen it with coach_notes but it could happen with any key.