Why am i getting this error TypeError: Object of type bytes is not JSON serializable

I have the below code, when i run it i get this error in my jupyter notetbook: TypeError: Object of type bytes is not JSON serializable.

import pyodbc 
conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
                      'Server=LDN01939344;'
                      'Database=EData;'
                      'Trusted_Connection=yes;'
                     )

sql = 'SELECT top 100 * from EData.dbo.DTData'
data = pd.read_sql(sql,conn)

app = dash.Dash(__name__)
app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in data.columns],
    data=data.to_dict('records'),
    
     style_header={
        'backgroundColor': 'rgb(230, 230, 230)',
        'fontWeight': 'bold'
    }
    
)

if __name__ == '__main__':
    app.run_server(debug=False,ssl_context='adhoc')

then i get that error- any idea what i can do???

Sounds like something in either your columns or data is a byte string b'text' rather than a unicode string. I’m not familiar with all the options in pyodbc.connect and pd.read_sql, there may be a way to tell those to do the decoding for you; otherwise you can do something like

columns=[{"name": i.decode(), "id": i.decode()} for i in data.columns]

and a list & dict comprehension to accomplish the same for data - perhaps with .decode('utf-16') or something if it’s not the default utf-8 encoding.