Skip to content

jsonify_string

fastagency.helpers.jsonify_string #

jsonify_string(line: str) -> str
Source code in fastagency/helpers.py
def jsonify_string(line: str) -> str:
    line_parts: list[str] = []
    for result in extract_json_objects(line):
        if isinstance(result, dict):  # got a JSON obj
            line_parts.append(f"\n```\n{json.dumps(result, indent=4)}\n```\n")
        else:  # got text/non-JSON-obj
            line_parts.append(result)
    # (don't make that a list comprehension, quite un-readable)

    return "".join(line_parts)