1

I'm trying to upload a list of lists as JSON using df.to_sql but it always upload with double quotes around it.

Desired output:

A header Geometry
First [[12.3, 45.6], [7.8, 9.1]]
Second [[12.3, 45.6], [7.8, 9.2]]

Current output:

A header Geometry
First "[[12.3, 45.6], [7.8, 9.1]]"
Second "[[12.3, 45.6], [7.8, 9.2]]"

Uploading snippet:

def upload_df(connection, df, table_name):
    dtype = { 
        'Geometry':JSON
    }
    schema = "schema"
    df.to_sql(table_name, connection,schema=schema,if_exists='replace',index=False, chunksize=1000, dtype=dtype)

Not sure if this is enough info to get help on this.

Thanks

Anon Li
  • 561
  • 1
  • 6
  • 18
  • Are you sure the `Geometry` column in the dataframe is a list, not a string? – Barmar Apr 29 '21 at 23:26
  • Because your `dtype` value is supposed to be the way to do it. See https://stackoverflow.com/a/41469431/1491895 – Barmar Apr 29 '21 at 23:27

0 Answers0