Creating an AI chat, fed internal data, powered by OpenAI and articulated through Make.com,
What is the problem & what have you tried?
I have an AI chat powered by a make scenario. All goes well : the question is transfered, the data to answer selected, the answer compiled by an OpenAI module and then sent to a webhook to be sent back to the chat.
However, the answer doesn’t reach it and I only get an error message. What is weirder is that when I put the text content of the JSON instead of the JSON itself, it gets transfered fine to the chat.
Module 1 : Webhook / receives the question asked in Chat
Module 2 : OpenAI / selects the theme of the question among set choices
Module 3 : Airtable / gathers data relevant to the theme previously identified
Module 4 : Text aggregator / compiles data in one text
Module 5 : OpenAI 2 / answers the question based on acquired data
Module 6 : Webhook 2 / sends the answer back to the chat
Escaping strings before mapping into another JSON string
Most of the time, you cannot directly map variables containing text content into another JSON string without escaping them, as the variable might contain special characters that are reserved. Special characters in JSON needs to be escaped (encoded) as a “literal” character, otherwise they make the whole JSON invalid when you map the variable value when creating another JSON string.
You can escape string variables by passing the text into the “Transform to JSON” module. You can also build a valid JSON string by using a Data Structure with the “Create JSON” module. Then, you can map the output of the Transform module into another JSON string, or simply use the whole output of the Create module.
Note:
When using the “Transform to JSON” module, the output should already contain the double quotes " " around your text, so when you map this output into your JSON, you should not need to wrap another pair of double quotes around it.
Alternatively, you can use the built-in function replace to replace those special characters with their escaped versions. To do this, simply paste this into the field, and replace the 1.text variable: