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.
Answers:
Wrap curly braces around it to get valid JSON syntax for an object.
result = json.loads('{' + bad_json + '}')
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.
Wrap curly braces around it to get valid JSON syntax for an object.
result = json.loads('{' + bad_json + '}')