Issue with useage of JSON output an citation

I am having trouble with the OpenAI API. I have not seen this anywhere.

After calling the API, the thread message returns the following value. I am not able to parse it into JSON and use the JSON keys. Because of the tripple quotes at the start and end. And the type of response.

```json [ { "name": "Proportion of women in management", "unit": "in %", "year": "2021", "value": "16.3", "page": "81" }, { "name": "Proportion of women in management", "unit": "in %", "year": "2020", "value": "15.13", "page": "81" }, { "name": "Proportion of women in management", "unit": "in %", "year": "2019", "value": "14.3", "page": "81" }, { "name": "Internationalization in top management", "unit": "in %", "year": "2021", "value": "20.3", "page": "81" }, { "name": "Cumulative diversity index figure", "unit": "Value", "year": "2021", "value": "127", "page": "81" }, { "name": "Target cumulative diversity index figure", "unit": "Value", "year": "2021", "value": "129", "page": "81" } ] ```【11†source】【13†source】

I do not understand the output of some citations and how to convert them or use the start_index.

I hope you may be able to help.

SyncCursorPage[ThreadMessage](data=[ThreadMessage(id='msg_4GiDd6Ua1udr8M7ODmu4yRPA', assistant_id='asst_kuDM1fyiRBFNc63wVreeLulx', content=[MessageContentText(text=Text(annotations
=[TextAnnotationFileCitation(end_index=998, file_citation=TextAnnotationFileCitationFileCitation(file_id='file-1CXIF5kP6tIsB3tJfdgnNoAP', quote='DIVERSITY KPIS\n\n\nKPI\nDiversity 
index\nProportion of women in management \n\n\nUnit\n\n\n  Target for proportion of women in management\n  Actual proportion of women in management\n  Actual level of proportion of
 \n  women sub-index | weighting 0.50\nInternationalization in top management\n  Target figure for internationalization\n  in top management\n  Actual figure for internationalizati
on\n  in top management\n  Actual level of proportion of \n  women sub-index | weighting 0.50\nCumulative diversity index figure\n  Target cumulative diversity index figure\n  Actu
al cumulative diversity index figure\nProportion of women (as per legal situation in Germany: \nExecutive Positions Act ) \n\n\nin %\nin %\n\n\nin %\n\n\nin %\n\n\nValue\nValue\n\n
\nProportion of women in first management level4\n\n\n  Target figure for women at first management level\n  Actual figure for women at first management level\nProportion of women 
in second management level5\n\n\n  Target figure for women at second \n  management level\n  Actual figure for women at second \n  management level\nDiscrimination\nDismissals due 
to breaches\nin the area of discrimination6 \n\n\nin %\nin %\n\n\nin %\n\n\nin %\n\n\nNumber \n\n\n2021'), start_index=987, text='【11†source】', type='file_citation')], value='```
json\n[\n    {\n        "name": "Proportion of women in management",\n        "unit": "in %",\n        "year": "2021",\n        "value": "16.3",\n        "page": "81"\n    },\n    
{\n        "name": "Proportion of women in management",\n        "unit": "in %",\n        "year": "2020",\n        "value": "15.13",\n        "page": "81"\n    },\n    {\n        "
name": "Proportion of women in management",\n        "unit": "in %",\n        "year": "2019",\n        "value": "14.3",\n        "page": "81"\n    },\n    {\n        "name": "Inter
nationalization in top management",\n        "unit": "in %",\n        "year": "2021",\n        "value": "20.3",\n        "page": "81"\n    },\n    {\n        "name": "Cumulative di
versity index figure",\n        "unit": "Value",\n        "year": "2021",\n        "value": "127",\n        "page": "81"\n    },\n    {\n        "name": "Target cumulative diversit
y index figure",\n        "unit": "Value",\n        "year": "2021",\n        "value": "129",\n        "page": "81"\n    }\n]\n```【11†source】【13†source】'), type='text')], create
d_at=1705064479, file_ids=[], metadata={}, object='thread.message', role='assistant', run_id='run_md9aMT5nj8isOUq8V5suQZEU', thread_id='thread_p3N7xONBZUdx4IAC4VkW7JjB'), ThreadMes
sage(id='msg_v8jTR3oGYy9E47VKlGBcbUf7', assistant_id=None, content=[MessageContentText(text=Text(annotations=[], value='Suche nach folgenden Kennzahlen: . Jede Kennzahl soll folgen
de Schlüssel haben: "name", "unit", "year", "value", "page". Ohne zusätzlichen Text. Bitte stelle sicher, dass jeder Schlüssel nur einen Wert hat. in einem validen JSON-Format'), t
ype='text')], created_at=1705064465, file_ids=['file-1CXIF5kP6tIsB3tJfdgnNoAP'], metadata={}, object='thread.message', role='user', run_id=None, thread_id='thread_p3N7xONBZUdx4IAC4VkW7JjB')], object='list', first_id='msg_4GiDd6Ua1udr8M7ODmu4yRPA', last_id='msg_v8jTR3oGYy9E47VKlGBcbUf7', has_more=False)

json_data = json_data.strip('` \n')

if json_data.startswith('json'):
    json_data = json_data[4:]  # Remove the first 4 characters 'json'

This was how I solved it.
I believe you might also be able to use JSON mode, but I’m not sure if it only works with chat completions.