Easily strip quotes and commas from JSON results

A simple problem with a simple solution if you are Javascript-aware.

While learning n8n, I set up a daily script which sends out a Movie Quote and the weather forecast and inserts these results into a SQL table. The workflow runs successfully every day except that more often than not, the SQL step failed with a corrupted INSERT statement.

The cause is in the text from the Movie Quotes site - when I come to INSERT today’s quote, I found that it often contains apostrophes and commas. SQL does not like these as it confuses them with string terminators. So I wanted to strip them out - I knew I had to use Javascript but not how. After some googling …

In my SQL node, I modified the JSON node statement I selected from the Movie Quote Node from this:

{{$node[“Get Today’s Movie Quote”].json[“quote”]}}

to this:

{{$node[“Get Today’s Movie Quote”].json[“quote”].replace(/[’,]+/g, ‘’)}}

Simple when you know how !

1 Like