I am using a survey tool called Qualtrics, in that I am creating a workflow which pulls data from an API. the returned Data is in the following format:
{"feedback_type":"Dining","reservation_id":"1234","order_id":null,"recommend_to_friend":"No","overall":"2","food":"3","ambience":"4","service":"5","notes":"The food was \"AWESOME\""}
The data is in JSON format, this then gets used in the next task in the workflow called as the code task (uses JavaScript) so that we can process this data.
What I am doing is
JSON.parse(`{"feedback_type":"Dining","reservation_id":"1234","order_id":null,"recommend_to_friend":"No","overall":"2","food":"3","ambience":"4","service":"5","notes":"The food was \"AWESOME\""}`)
Which is failing due to double quote breaking the JSON format.
This is the only way I can pull data in the code task (in a string).
I tried using regex to replace the problemeatic double quote but i was not able to figure out way to only remove/replace the one we wanted gone.
You cannot simply copy/paste a raw output string in your code and expect it to work. In Javascript source code you either need to escape backslashes by doubling them, or, preferably, use String.raw
:
result = JSON.parse(String.raw`{"feedback_type":"Dining","reservation_id":"1234","order_id":null,"recommend_to_friend":"No","overall":"2","food":"3","ambience":"4","service":"5","notes":"The food was \"AWESOME\""}`)
console.log(result)
console.log(result.notes)