top of page
  • Writer's pictureNocode AI

Make.com: Escaping Special Characters in JSON

As a Make.com user, you may have encountered the need to escape special characters in JSON. JSON (JavaScript Object Notation) is a widely used data interchange format, but it can be challenging to handle certain characters that have special meaning within JSON  for Nocode Developer.


Understanding the Challenge of Json format in Make.com

JSON is a lightweight data format that is easy for humans to read and write. It is commonly used for data transmission between a server and a web application. However, certain characters have special meaning in JSON, such as double quotes ("), backslashes (\), and control characters.

  • Backspace is replaced with \b

  • Form feed is replaced with \f

  • Newline is replaced with \n

  • Carriage return is replaced with \r

  • Tab is replaced with \t

  • Double quote is replaced with "

  • Backslash is replaced with \

These special characters can cause parsing errors or unintended behavior if not properly escaped.


The challenge lies in finding a way to escape these special characters in JSON to ensure that the data is correctly interpreted by both the sender and the receiver.


While Make.com does not provide a default way to escape special characters in JSON, there are alternative approaches that can be used to overcome this limitation.


Leveraging the Set a Variable Module

One approach to escaping special characters in JSON on Make.com is to utilize the "Set a Variable" module. This module allows you to define a variable and set its value using various functions, including the replace() function. By nesting multiple replace() functions, you can recursively apply different replace tasks to escape the special characters.

Here's an example of how you can use the "Set a Variable" module with nested replace() functions:

Set a Variable:
   Variable Name: escapedJSON
   Variable Value: replace(replace(replace(JSON, "\"", "\\\""), "\\", "\\\\"), "\n", "\\n")

In this example, we are replacing double quotes (") with \", backslashes (\) with \\, and newline characters with \n. By applying these replacements recursively, we ensure that the special characters are properly escaped in the JSON string.


Requesting a Feature

While the above approach provides a workaround for escaping special characters in JSON on Make.com, it can be cumbersome and less efficient compared to having a dedicated function for escaping JSON. If you find yourself frequently needing to escape special characters in JSON, you can join other Make.com users in requesting a dedicated "Escape JSON" function. By expressing your need for this feature and providing your use cases, you can contribute to the development of Make.com and potentially influence the inclusion of this feature in future updates.

You can submit your feature request on the Make.com platform-ideas page dedicated to this topic. Here is the link to the page: Make.com Platform Ideas - Functions: Escape JSON Function


Summary

Escaping special characters in JSON is a crucial step to ensure the integrity and correct interpretation of data. While Make.com does not provide a default way to escape special characters in JSON, there are alternative approaches you can take. Utilizing the "Set a Variable" module with nested replace() functions can be an effective workaround. Additionally, you can request a dedicated "Escape JSON" function on the Make.com platform-ideas page to contribute to the development of Make.com.


In the meantime, manual escaping, external libraries, and Make.com's string functions can be utilized to escape special characters in JSON. By being aware of these techniques and best practices, you can confidently work with JSON on Make.com and overcome the challenges posed by special characters.



Additional Resources:


392 views0 comments

Comments


bottom of page