Json String value doesnt work with HTTP "Make a Request module"

Hi,

I have a HTTP “Make a Request Module” (This request sends to groq AI)

I have a JSON string value within the prompt section of the HTTP module

When i run this I get this error:

" DataError

Error: 400 Bad Request

  • {“error”:{“message”:“failed to unmarshal JSON: invalid character ‘s’ after object key:value pair”,“type”:“invalid_request_error”}}"

However when i directly embed the content found in the JSON string value it works fine.

Does anybody know why this might be happening?

I would assume this is because you are not escaping special characters within the JSON string variable. Can you please share the output of the variable. You need to make sure you escape these .

  • If your JSON string contains special characters (like quotes), ensure they are properly escaped. For example, replace double quotes " with \".

Also, Since you mentioned that directly embedding the content works fine, try comparing the directly embedded content with the JSON string value to identify any discrepancies. What is the difference between them.

1 Like

Thanks for the response, here is the output of the “Parse JSON” module im using (this output is the one being mapped into the HTTP make a request modudle.

Output.txt (11.4 KB)

I’m not too familair with the escaped JSON. Am I able to convert this before the HTTP module?

(the text is large as i’m grabbing the HTML code of a website)

thanks!

So the issue looks like it is being cause by the special characters being unescaped.

Using a replace function will help you escape the characters.

create a new variable before the HTTP and then set this variable as the new content value

{{replace(replace(replace(yourJSONstring, "", “\\”), “"”, “\"”), “\n”, “\n”)}}

I have made a “Get a variable” module and added this in the value

When i put this in the HTTP module it doesnt appear to register whats in the varibale.

Have i done this right or am i being stupid? I apprecaite the help!

Hi the copy and paste was weird.

I am uploading a blueprint with just the variable.
blueprint (26).json (2.4 KB). Import it to a new scenario then just copy and paste it into your scenario.

3 Likes

Thank you so much for the help, this worked perfectly, all working now! I have been working on this issue for hours :smile:

1 Like

Woohooo so happy it worked. Enjoy!

1 Like

I think there was a simpler solution.

In your first screenshot you are adding a JSON string variable to a JSON.

If the JSON string variable was created using a Transform to JSON module, then it already comes double quotes before and after.

So all you had to do was remove the double quotes around the variable in your first screenshot.

Instead of

"20.JSON"

remove the quotes around it

20.JSON

No need to replace anything.

samliewrequest private consultation

Join the unofficial Make Discord server to chat with us!

Hi Sam,

Thanks for the reply,

So this is interesting, could you help me make sense of it please?

When I remove the " " as suggested it works fine when only the value is present (please see below)

However when I put any form of text in front of it as seen below it doesn’t work. do you know why this might be? My guess is that the text im putting before isnt correctly formatted to a JSON string or something along those lines?

Your JSON string already contains something like this:

"my json string"

By adding additional text to it, it is no longer a “string” because it’s OUTSIDE the double quotes.

summarize the following text:"my json string"

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

2 Likes