Category: How do I do X?

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Replace ’ from json String


I am having an issue using JSON data in an MSSQL query. The JSON data contains single quotes that need to be replaced with double single quotes to avoid syntax errors in the query. I tried using the replace() function in JavaScript, but it resulted in an error. Ultimately, with the help of Amelia, I successfully used JSON.parse() and JSON.stringify() to replace the single quotes.


The user had a JSON data with single quotes, which was causing a syntax error in their MSSQL query. To solve this, they needed to replace the single quotes with escaped single quotes ("''").

Initially, they tried using the replace() function in JavaScript to replace the single quotes. However, this resulted in an error as the JSON data was not a string.

To solve this, they used the JSON.stringify() and JSON.parse() functions in JavaScript to convert the JSON to a string, replace the single quotes, and then parse it back to JSON format. They used the replaceAll() function to replace all occurrences of single quotes.

The final code looked like this:

{{JSON.parse(JSON.stringify("'", ""))}}

This solution resolved the syntax error in the MSSQL query caused by single quotes in the JSON data.