d09 · Extract JSON from a reply (~6 min)
Parsing strings. Edit drills.py. Standard library only; no model calls, no API key.
def extract_json(text):
Return the first JSON object (a dict) in a model's reply.
It may be the whole reply, inside a json or plain fence, or surrounded by
prose that can itself contain braces. Braces inside JSON strings are part of the
object. Raise ValueError if the reply holds no JSON object.
Failure messages are enough to go on, so leave the tests unread until you submit.