From 19b5cb1e1079506490e82222f14d322b5fe3af4f Mon Sep 17 00:00:00 2001 From: John Wang Date: Fri, 2 Jun 2023 17:34:24 +0800 Subject: [PATCH] feat: fix json end with `` (#285) --- api/libs/json_in_md_parser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/libs/json_in_md_parser.py b/api/libs/json_in_md_parser.py index b2dba695cc..2586d77d03 100644 --- a/api/libs/json_in_md_parser.py +++ b/api/libs/json_in_md_parser.py @@ -13,6 +13,12 @@ def parse_json_markdown(json_string: str) -> dict: if start_index != -1 and end_index != -1: extracted_content = json_string[start_index + len("```json"):end_index].strip() + # Parse the JSON string into a Python dictionary + parsed = json.loads(extracted_content) + elif start_index != -1 and end_index == -1 and json_string.endswith("``"): + end_index = json_string.find("``", start_index + len("```json")) + extracted_content = json_string[start_index + len("```json"):end_index].strip() + # Parse the JSON string into a Python dictionary parsed = json.loads(extracted_content) elif json_string.startswith("{"):