I got struck with openrouter http request its showing JSON parameter needs to be valid JSON

Describe the problem/error/question

{
“model”: “google/gemini-3-pro-image-preview”,
“messages”: [
{
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: “{{ $json.output.full_prompt }}”
},
{
“type”: “image_url”,
“image_url”: {
“url”:“{{ $(‘Image Edit Fields’).item.json.data1 }}”
}
}
]
}
],
“modalities”: [“image”]
}

What is the error message (if any)?

Problem in node ‘Generate Image‘

JSON parameter needs to be valid JSON

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

{
“errorMessage”: “JSON parameter needs to be valid JSON”,
“errorDetails”: {},
“n8nDetails”: {
“nodeName”: “Generate Image”,
“nodeType”: “n8n-nodes-base.httpRequest”,
“nodeVersion”: 4.3,
“itemIndex”: 0,
“time”: “05/12/2025, 19:54:20”,
“n8nVersion”: “1.122.5 (Self Hosted)”,
“binaryDataMode”: “default”,
“stackTrace”: [
“NodeOperationError: JSON parameter needs to be valid JSON”,
" at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:441:15)“,
" at processTicksAndRejections (node:internal/process/task_queues:105:5)”,
" at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1074:8)“,
" at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1255:11)”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1691:27",
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2307:11"
]
}
}

Information on your n8n setup

  • n8n version:

  • Database (default: SQLite):

  • n8n EXECUTIONS_PROCESS setting (default: own, main):

  • Running n8n via (Docker, npm, n8n cloud, desktop app):

  • Operating system:

Try replacing your

image

with
“text”: “{{ JSON.stringify($json.output.full_prompt).slice(1, -1) }}”

Still its showing the same error
i making with use of this youtube video the same workflow but its not working for me

Hey @Harish_Balasubramani !

As you can see in the video, the url is passing a base64 string , and you are using a node expression that as well may contain characters that may break the json (“,*,’ etc …).

And for the prompt you can use the expression mentioned by

But a bit different :

“text”: {{JSON.stringify($json.output.full_prompt)}}

so new lines get escaped as well…

Give it a try.

Cheers!

its showing error still in that video i got error in generate image http node

Use exactly like this:

“text”: {{JSON.stringify($json.output.full_prompt)}}

Notice the outer double quotes are removed. JSON.stringify() wraps the resulting escaped string in its own quotes.

​Escapes Speecial Charactrd It converts characters like double quotes (“) into \” and newlines (\n) into \\n so they are valid inside a JSON string.

​It autoomatically wraps the resulting, escaped strig in its own pair of double quotes.

still the same i will add the reference screenshot from youtube the same workflowi was doing and still im getting same error “JSON parameter needs to be valid JSON”

Try to grad and drop directly the “full_prompt” string into that place…

And if you check the text inside the prompt(video), it doesn’t contain any character (“,\n) that can break json.

Either you stringify, or be sure that the “full_prompt” arrives escaped (so all the characters that may break json to be cleared)…

1 Like

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