Best answer

Removing quote symbols from a hook catch

  • 3 November 2020
  • 6 replies
  • 637 views

Hello guys,

I’m facing a probably simple problem. I’m building a form that sends the data thru a webhook as JSON. The problem is that if the end user completes the form and uses quote symbols the webhook will error out and the zap will halt.

 

How can I remove any quote symbols or anything that could error out when sending a JSON payload?

icon

Best answer by CraigNet3 5 November 2020, 16:08

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Nobody has a solution?

Userlevel 4
Badge +4

@robertbant you can try changing the Webhook trigger action to “catch raw”. If you do that, Zapier won’t parse the JSON from your request. However, you’ll still need to manually parse it in the next step in order to get the data as fields. The best way to do that is to use a Code By Zapier action, replace the double quotation marks in your raw JSON string with single quotation marks, then do a JSON.parse(jsonstring) to turn your raw JSON string into an object with fields, which can be returned for other steps. 

@robertbant you can try changing the Webhook trigger action to “catch raw”. If you do that, Zapier won’t parse the JSON from your request. However, you’ll still need to manually parse it in the next step in order to get the data as fields. The best way to do that is to use a Code By Zapier action, replace the double quotation marks in your raw JSON string with single quotation marks, then do a JSON.parse(jsonstring) to turn your raw JSON string into an object with fields, which can be returned for other steps. 

 

Thanks for the answer Craig.

 

The thing is, there shouldn't be any quotation marks, what im trying to do is an insurance, if someone puts quotation marks to be removed.

 

Also, can you share a code exemple how to remove or change the quotation marks?

Userlevel 4
Badge +4

Here is the setup for the Catch Raw Hook…

 

Let’s say your raw JSON is:

{"key":""value""}

Here is the code to parse it:

//Take the rawJson input and replace all instances of double quotes with single quotes
var rawJson = inputData.rawJson.replace(/\:\"\"/g, ':"' + "'").replace(/\"\"/g,"'" + '"');

//Parse the rawJson and return the result
return {json: JSON.parse(rawJson)}

Here is how the result would look:

 

Here is the setup for the Catch Raw Hook…

 

Let’s say your raw JSON is:

{"key":""value""}

Here is the code to parse it:

//Take the rawJson input and replace all instances of double quotes with single quotes
var rawJson = inputData.rawJson.replace(/\:\"\"/g, ':"' + "'").replace(/\"\"/g,"'" + '"');

//Parse the rawJson and return the result
return {json: JSON.parse(rawJson)}

Here is how the result would look:

 

Hey Craig,

I just noticed that the data is coming using the involve.me app like this:

key=value

 

Userlevel 4
Badge +4

@robertbant can you post a sample of the payload from the raw catch hook please?