Is there a simple way to validate json?

  • 23 December 2022
  • 1 reply

Userlevel 1

I have a number of zaps that receive data via a webhook.  I then need to build a different json string using SOME of those fields, some other custom data, etc. to post to a different api using a separate webhook action.  It’s pretty simple, and all works well until some of my fields have invalid characters in them - like quotes or a backslash.  These end up invalidating the json because they are interpreted as string termination or an escape character by the system receiving the json.  In my case, it’s Splunk sending data to a listening Zapier webhook, which I then manipulate and send to a Cisco WebEx space using a custom webhook action.

I can fix this by adding a “formatter” action and doing a string replace on any given field for any given character, but when I’m building a json string of say 15 different fields from my initial input, all of which “might” have a “ or a \, then that’s a very inefficient way to format.  What would be ideal if there was a simple “validate json” action, or even a checkbox on the webhook action that simply did this for me.  json is an industry standard - that act of replacing \ with \\ or “ with \” is something you’d have to do ANY time you are sending json somewhere.  So essentially, instead of me building a mile long zap with a hundred string.replace actions in it, is there a better way to simply validate (and correct) json?

The webhook action gives you a data field to build the json.  Even if there were some other action that let me build my json as a simple string in the same way the “data” field on the webhook works, that I can then pass in to a formatter action to replace strings on the entire json string (instead of individual fields), and THEN pass to the webhook action, that would be an improvement also (even though I’m still doing my own json corrections here, it seems like a pretty simple and awesome thing for Zapier to have an action for).

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

1 reply

Userlevel 7
Badge +14

Hi @jrolfe 

Good question.

Often it can be more efficient to use 1 Code step (JavaScript/Python) to handle data instead of multiple Formatter steps in a Zap.


You could also try to construct the desired JSON in 1 Formatter step with multiple variables mapped, and do a replace that way instead.


Feedback and feature requests can be submitted via a ticket to Zapier Support to be logged: