MCPcopy Create free account
hub / github.com/pollinations/pollinations / parse_json_response

Function parse_json_response

social/scripts/common.py:124–138  ·  view source on GitHub ↗

Parse JSON from AI response, stripping markdown fences.

(response: str)

Source from the content-addressed store, hash-verified

122
123
124def parse_json_response(response: str) -> Optional[Dict]:
125 """Parse JSON from AI response, stripping markdown fences."""
126 text = response.strip()
127 if text.startswith("```"):
128 lines = text.split("\n")
129 lines = lines[1:] # remove opening fence (may include language specifier)
130 if lines and lines[-1].strip().startswith("```"):
131 lines = lines[:-1] # remove closing fence
132 text = "\n".join(lines)
133 try:
134 return json.loads(text)
135 except json.JSONDecodeError as e:
136 print(f" JSON parse error: {e}")
137 print(f" Response: {text[:500]}")
138 return None
139
140
141def get_repo_root() -> str:

Callers 6

generate_digestFunction · 0.90
generate_discord_postFunction · 0.90
generate_summaryFunction · 0.90
render_ai_reportFunction · 0.90
analyze_prFunction · 0.90
generate_platform_postFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected