# JSON parameter needs to be valid JSON on an HTTP request

**URL:** <https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824>\
**Category:** Questions\
**Tags:** node, http-request\
**Created:** [September 2, 2025, 5:02pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824 "2025-09-02T17:02:13Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Armand\_Ferveur](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/armand_ferveur/32/59217_2.png) [@Armand\_Ferveur](https://community.n8n.io/u/Armand_Ferveur)\
**Post date:** [September 2, 2025, 5:02pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/1 "2025-09-02T17:02:13Z")

</div>

Hey, I tried to call the Gemini 2.5 flash image model via HTTP request, but I’m getting this error that I can’t seem to resolve in the JSON code. I feel like I’m doing it right, and ChatGPT doesn’t see any errors either. If anyone knows how to fix it, I’m all ears 😅

I also tried to use the “stringify” function in the code directly and in an external code node to change the format, but it’s not working either. 😭

Thank you in advance

 ![Capture d’écran 2025-09-02 174723](https://europe1.discourse-cdn.com/n8n/original/3X/3/1/318cdae8a41d6031b85fba8d79c745e90ba16f07.png)

 ![Capture d’écran 2025-09-02 174751](https://europe1.discourse-cdn.com/n8n/original/3X/c/9/c98a25773d3a5a881a28bc9a917dc9616ed00f5c.png)

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:04pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/2 "2025-09-02T17:04:26Z")

</div>

Change your `"{{ $json.prompt}}"`  
to  
`"{{ $json.prompt.toJsonString() }}"`

Without `toJsonString()`, the raw value may break JSON parsing (especially if it contains quotes, line breaks, or special characters).  
Using `.toJsonString()` makes sure the value is escaped properly and produces valid JSON.

Otherwise you can use `JSON.stringify()` function, but you can use the `.toJsonString()` method also.

---

<div class="post-metadata">

**Author:** ![mohamed3nan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mohamed3nan/32/188347_2.png) [@mohamed3nan](https://community.n8n.io/u/mohamed3nan)\
**Post date:** [September 2, 2025, 5:04pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/3 "2025-09-02T17:04:56Z")

</div>

Hi @Armand_Ferveur

This is a common issue,

Could you please try to use `JSON.stringify()` like this:

```auto
"text": {{ JSON.stringify( $json.prompt) }}

```

* * *

> **⚡**
>
> 👉 If this solves your problem, feel free to mark the reply as the solution ✅ it’ll help others with same issue, and it also helps me on the leaderboard 🙏🏻

---

<div class="post-metadata">

**Author:** ![Armand\_Ferveur](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/armand_ferveur/32/59217_2.png) [@Armand\_Ferveur](https://community.n8n.io/u/Armand_Ferveur)\
**Post date:** [September 2, 2025, 5:09pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/4 "2025-09-02T17:09:43Z")

</div>

Doesn’t work either 😅 sry

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/2/b24760e54fdd39180a597d4f19df451b8c273621.png)

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:10pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/5 "2025-09-02T17:10:10Z")

</div>

Use mine 😃

---

<div class="post-metadata">

**Author:** ![Armand\_Ferveur](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/armand_ferveur/32/59217_2.png) [@Armand\_Ferveur](https://community.n8n.io/u/Armand_Ferveur)\
**Post date:** [September 2, 2025, 5:10pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/6 "2025-09-02T17:10:42Z")

</div>

> [@withabdul](#):
>
> “{{ $json.prompt.toJsonString() }}”

same

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/5/b58453c9f0a22bd22536ff0e9f83438a0a9c2f26.png)

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:12pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/7 "2025-09-02T17:12:33Z")

</div>

can you share the output here?  
before you running it

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:15pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/8 "2025-09-02T17:15:09Z")

</div>

By the way, Why don’t you use the Gemini node, why you using HTTP node for that?

---

<div class="post-metadata">

**Author:** ![jabbson](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jabbson/32/87328_2.png) [@jabbson](https://community.n8n.io/u/jabbson)\
**Post date:** [September 2, 2025, 5:15pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/9 "2025-09-02T17:15:38Z")

</div>

When using `.toJsonString()`, remove the quotation marks in the JSON body:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/c/b/cb5451402f77f55af05c461c35999534cb99f07c.png)

here is what it supposed to be:

```auto
{
  "contents": [
    {
      "parts": [
        {
          "text": {{ $json.prompt.toJsonString() }}
        }
      ]
    }
  ]
}

```

Otherwise you will end up with two quotation marks in the beginning and two at the end.

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:16pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/10 "2025-09-02T17:16:39Z")

</div>

```auto
{
  "contents": [
    {
      "parts": [
        {
          "text": "{{ $json.content.toJsonString() }}"
        }
      ]
    }
  ]
}

```

Use this, your JSON is wrong, since array cannot use key-value for that.  
You need add one more object `{}` the curly branches which handle the `text` field

---

<div class="post-metadata">

**Author:** ![Armand\_Ferveur](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/armand_ferveur/32/59217_2.png) [@Armand\_Ferveur](https://community.n8n.io/u/Armand_Ferveur)\
**Post date:** [September 2, 2025, 5:21pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/11 "2025-09-02T17:21:07Z")

</div>

still not working 😅 I rly don’t know, i’ve allready done everything you’ve told me but it’s still doen’t want to work.

(btw, i didn’t use Gemini node because i didn’t knew it existed 😂 i’ll probably do that instead 🤣 )

---

<div class="post-metadata">

**Author:** ![Armand\_Ferveur](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/armand_ferveur/32/59217_2.png) [@Armand\_Ferveur](https://community.n8n.io/u/Armand_Ferveur)\
**Post date:** [September 2, 2025, 5:22pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/12 "2025-09-02T17:22:39Z")

</div>

it worked 🫡

ALLELUIA MY FRIEND

Thx everyone 💖

---

<div class="post-metadata">

**Author:** ![withabdul](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/withabdul/32/179439_2.png) [@withabdul](https://community.n8n.io/u/withabdul)\
**Post date:** [September 2, 2025, 5:22pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/13 "2025-09-02T17:22:44Z")

</div>

Hahahaa, yeah you can use the Gemini node by the way, easier for you to create AI things with the built in node:D

---

<div class="post-metadata">

**Author:** ![mohamed3nan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mohamed3nan/32/188347_2.png) [@mohamed3nan](https://community.n8n.io/u/mohamed3nan)\
**Post date:** [September 2, 2025, 5:28pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/14 "2025-09-02T17:28:57Z")

</div>

Weird how `.toJsonString()` working and `JSON.stringify()` not in this case!  
do you know the reason @jabbson ?

---

<div class="post-metadata">

**Author:** ![jabbson](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jabbson/32/87328_2.png) [@jabbson](https://community.n8n.io/u/jabbson)\
**Post date:** [September 2, 2025, 5:33pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/15 "2025-09-02T17:33:21Z")

</div>

Both worked for me:

---

<div class="post-metadata">

**Author:** ![mohamed3nan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mohamed3nan/32/188347_2.png) [@mohamed3nan](https://community.n8n.io/u/mohamed3nan)\
**Post date:** [September 2, 2025, 5:34pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/16 "2025-09-02T17:34:02Z")

</div>

Yeah, I was going insane for a second lol 😅 Thanks, I can go now 😄

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [September 9, 2025, 5:34pm UTC](https://community.n8n.io/t/json-parameter-needs-to-be-valid-json-on-an-http-request/180824/17 "2025-09-09T17:34:06Z")

</div>

Closed on September 9, 2025, 5:34pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
