Why double quotes are being escaped in JSON.stringify but not single quotes

86 views Asked by At

I'm creating a json object string that has single quote in the condition which need to be use in sql query. Something like this,'field IN ('ab'c'd')' so instead I tried using double quotes for the condition like this 'field IN ("ab'c'd")' which on doing stringify gives 'field IN (\"ab'c'd\")'.

Now this messes the whole sql query since the query is trying to execute SELECT * FROM WHERE field IN (\"ab'c'd\") instead of SELECT * FROM WHERE field IN ("ab'c'd").

How to work around this?

I tried using JSON.stringify(s).replace(/\\"/g, '"') but still looking for any other way. I'have two different db SQL and neo4j so I cant just skip ' using double ' I need to write different scenario for escaping the ' in each db.

0

There are 0 answers