initial commit
This commit is contained in:
16
test_repro.py
Normal file
16
test_repro.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import re
|
||||
import json
|
||||
|
||||
def safe_parse_json(text: str):
|
||||
start = text.find("{")
|
||||
end = text.rfind("}")
|
||||
print(f"text type: {type(text)}")
|
||||
print(f"start: {start}, end: {end}")
|
||||
if start != -1 and end != -1:
|
||||
json_str = text[int(start) : int(end) + 1]
|
||||
print(f"json_str: {json_str}")
|
||||
return json.loads(json_str)
|
||||
return None
|
||||
|
||||
test_text = "Filler text {\"key\": \"value\"} more filler"
|
||||
print(safe_parse_json(test_text))
|
||||
Reference in New Issue
Block a user