Error help: JSON parameter needs to be valid JSON

Can someone please help me where is the error, I tried a lot it is not working:

curl -X POST “https://api.together.xyz/v1/images/generations
-H “Authorization: Bearer $TOGETHER_API_KEY”
-H “Content-Type: application/json”
-d ‘{
“model”: “black-forest-labs/FLUX.1-dev”,
“prompt”: “{{ $json.output }}”,
“width”: 1024,
“height”: 768,
“steps”: 28,
“n”: 1,
“response_format”: “b64_json”,
“stop”:
}’

Under the prompt part, I have tried everything with or without quotation marks. still giving me the error that JSON parameter needs to be valid JSON during HTTP request

Hi @Aish_Ray, welcome to the community!

Could you please try using:

"prompt": {{ JSON.stringify($json.output) }}
3 Likes

@mohamed3nan
It worked man, I have from non coding background, I spent around 3 hours digging what to do, you saved my life
Thank you very mych

1 Like

So glad to hear it worked! :raised_hands:

Don’t hesitate to post any questions you have.

:bulb:Pro tip: try using the search feature to check if someone has faced a similar issue, there’s a huge knowledge base out there that can help you find solutions faster.

2 Likes


Again it is coming error @mohamed3nan
Please help

Error code:
{
“errorMessage”: “JSON parameter needs to be valid JSON [item 0]”,
“errorDetails”: {},
“n8nDetails”: {
“nodeName”: “HTTP Request”,
“nodeType”: “n8n-nodes-base.httpRequest”,
“nodeVersion”: 4.2,
“itemIndex”: 0,
“time”: “5/15/2025, 11:56:32 PM”,
“n8nVersion”: “1.91.3 (Cloud)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“NodeOperationError: JSON parameter needs to be valid JSON”,
" at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:266:23)“,
" at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:687:50)”,
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:921:62",
" at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1257:20"
]
}
}

Hi @Aish_Ray

When using JSON.stringify() remove the quotes " "

like this:

"prompt": {{ JSON.stringify($json.output) }}
1 Like

A code node can be added in front of the Http requests node to format the JSON.
{
“nodes”: [
{
“parameters”: {
“jsCode”: “const escapedOutput = $input.first().json.output\n .replace(/"/g, ‘\\"’) // 转义双引号\n .replace(/\n/g, ‘\\n’); // 转义换行符(如果JSON需要)\n\nreturn [{ json: { output: escapedOutput } }];”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
1120,
0
],
“id”: “6222d70a-7c64-49aa-a21b-b1312115a64f”,
“name”: “Code”
}
],
“connections”: {
“Code”: {
“main”: [

]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “98925ce57cc442f57c6f6a0da2215a4b8439638ec6609b160e8bd8cff8df23db”
}
}

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