I am loading a json data with large number of into snowflake. Some values of the json row contains single quotes and it is returing an error when I am trying to insert json into snowflake using parse_json . I am using sqlalchemy as a connector from python. Here is my code
connection.execute(
f'insert into json_demo select parse_json( """{json.dumps(data)}""" )')
The json data sample is as follows:
[
{
"name": "Milka Luam",
"ID": "124",
"UnitAddressLine1": "1262 University Runa",
"UnitCity": "Jas sti'n"
},
{
"name": "Rahu Liran",
"ID": "541",
"UnitAddressLine1": "1262 University Blina",
"UnitCity": "Rish 21"
},
...
]
The single quote in the unity city Jas sti'n is returning an error. Here is the error:
sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 001003 (42000): SQL compilation error:
syntax error line 1 at position 47 unexpected 'UnitCity'.
syntax error line 1 at position 47 unexpected 'UnitCity'.
parse error line 1 at position 90,841 near '<EOF>'.
I can't manually add an escape character as I am loading a large number of row.