OpenAI HTTP (legacy) 400 “We could not parse the JSON body” — Make mapping tokens causing invalid JSON?

,

:bullseye: What is your goal?

  1. I receive a Mindee response (module 29) containing a transactions array:
    29.data.inference.result.fields.transactions
  2. I set a variable (Tools → Set variable) called transactions_json using:
    toJSON(29.data.inference.result.fields.transactions)
  3. I pass that into my OpenAI request content inside messages.

:thinking: What is the problem & what have you tried?

As soon as I map the Make variable into the JSON request body, the OpenAI request fails with “invalid JSON”.
Request content currently looks like this in Make (simplified):
{
“model”: “gpt-4.1-mini”,
“temperature”: 0,
“response_format”: { “type”: “json_object” },
“messages”: [
{ “role”: “system”, “content”: “…” },
{ “role”: “user”, “content”: “…” },
{ “role”: “user”, “content”: “TRANSACTIONS_JSON:\n<Make mapped variable: 48.transactions_json>” }
]
}

What’s the correct way in Make to embed a mapped JSON string / array into an HTTP Raw JSON body so the final payload remains valid JSON?
Do I need to:
escape quotes/newlines differently?
use a different module (HTTP v2 / OpenAI module)?
build the body with Create JSON / Compose a JSON first rather than Raw?
or use parseJSON() + send it as an actual array (not a string)?
If helpful, I can paste the exact “Input” payload Make shows under the module run.

:clipboard: Error messages or input/output bundles

Screenshot 2026-01-24 at 21.38.48

Welcome to the Make community!

Modules Using Raw JSON

The HTTP “Make a request” or an app’s universal “Make an API call” modules uses raw JSON to transmit data. The HTTP body content field does not automatically escape variables mapped into it, and if the mapped variables contain JSON reserved characters (e.g. from the output of an AI module, or another JSON string), it breaks the structure of your outermost JSON.

Simple text string in the value is okay :white_check_mark:

Inserting special characters (like " and line-breaks), makes the JSON invalid. :cross_mark:

Correctly escaped special JSON characters in the value :white_check_mark:

Escaping Variables 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.

A. Using “Transform to JSON” Module

You can escape 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, or simply use the whole output of the Create module.

:warning: Note:

When using the “Transform to JSON” module on a string-type variable, the output should already contain the double quotes " " around your text, so when you map this output into your JSON, do not wrap another pair of double quotes around it!

B. Using “Replace” Function

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:

{{ replace(replace(1.text; "/([""\\])/g"; "\$1"); "/\r?\n\r?/g"; "\n") }}
:high_voltage: Make Input Markup: Copy-paste the above into the field, including start/end curly brackets for it to import as intended :warning:

Further Information

For more information on JSON and escaping special characters, see:

Hope this helps! If you are still having trouble, please provide more details.

@samliew

2 Likes

Thank you Samliew, I really appreciate the effort you have gone to on this, I will give it a try, and let you know if any issues !