Converting string to a json in Python

Question:

Im trying to convert the below string to json object using json.loads.

"Error":"Execution failed on sql 'SELECT * FROM tablename': ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Query timeout expired (0) (SQLExecDirectW)')"

Im getting the below error.

JSONDecodeError: Extra data: line 1 column 8 (char 7)

How do we convert the above string to json object

TIA.

Asked By: SanjanaSanju

||

Answers:

Wrap curly braces around it to get valid JSON syntax for an object.

result = json.loads('{' + bad_json + '}')
Answered By: Barmar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.