HTTP Request: JSON parameter needs to be valid JSON

Hi! Does anyone know how to tackle these errors and why?
Thanks!

JSON:
{
“phone”: “{{ $json.client_phone }}”,
“message”: “:mask: Clínica {{ $json.name }} :tooth:\n\nOlá {{ $json.client_name }}, tudo bem?\n\nPassando para lembrar seu horário, dia {{ $json.appointment_date }}, às {{ $json.appointment_time }} horas com {{ $json.dentista }}.\n\nPodemos confirmar sua consulta?”,
“optionList”: {
“title”: “Selecionar opções”,
“buttonLabel”: “Abrir lista de opções:”,
“options”: [
{
“id”: “1”,
“description”: “Confirmar”,
“title”: “SIM”
},
{
“id”: “2”,
“description”: “Reagendar”,
“title”: “NÃO”
}
]
}
}

Node version
4.2 (Latest)
n8n version
1.90.2 (Self Hosted)

  • n8n version: 1.90.2 (Self Hosted)
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu

Your json is not structured in correct json format

Share your JSON so we can help you spot the issue.
You can also use online JSON validators if you prefer.

{
“phone”: “{{ $json.client_phone }}”,
“message”: “:mask: Clínica {{ $json.name }} :tooth:\n\nOlá {{ $json.client_name }}, tudo bem?\n\nPassando para lembrar seu horário, dia {{ $json.appoitment_date }}, às {{ $json.appoitment_time }} horas com {{ $json.dentista }}.\n\nPodemos confirmar sua consulta?”,
“optionList”: {
“title”: “Selecionar opções”,
“buttonLabel”: “Abrir lista de opções:”,
“options”: [
{
“id”: “1”,
“description”: “Confirmar”,
“title”: “SIM”
},
{
“id”: “2”,
“description”: “Reagendar”,
“title”: “NÃO”
}
]
}
}

the issue is JSON expect straight double quotes but you are using curly quotes.

here is valid json:

{
   "phone":"{{ $json.client_phone }}",
   "message":":mask: Clínica {{ $json.name }} :tooth:\n\nOlá {{ $json.client_name }}, tudo bem?\n\nPassando para lembrar seu horário, dia {{ $json.appoitment_date }}, às {{ $json.appoitment_time }} horas com {{ $json.dentista }}.\n\nPodemos confirmar sua consulta?",
   "optionList":{
      "title":"Selecionar opções",
      "buttonLabel":"Abrir lista de opções:",
      "options":[
         {
            "id":"1",
            "description":"Confirmar",
            "title":"SIM"
         },
         {
            "id":"2",
            "description":"Reagendar",
            "title":"NÃO"
         }
      ]
   }
}
2 Likes

This question has been asked a lot recently, and it’s easy to find the answer with a quick search.

By the way, you can just use JSON.stringify()

So, update your JSON body expressions to something like this:

"name": {{ JSON.stringify( $json.anything ) }} 
3 Likes

Yerp, JSON.stringify() is my first thought on this too. It’s always worth using first fixes most time.

@King_Samuel_David yes no need to duplicate posts I guess…

2 Likes

Here is the quick way to check what is going on.

If you are sure about your expression is good.

Then check the preview result

Copy all the json string and go to some website call json validator

It will check which character is wrong.

In this case. There are 2 double quotes so it weng wrong.

""12345""

This is not a valid json. And there are many other reasons will cause invalid json as well

2 Likes

Sometimes folks miss the obvious stuff, and when I saw the thread, JSON.stringify() was the first thing that came to mind. I wasn’t trying to duplicate or over-post — just agreeing and adding that it’s often a great first fix that gets overlooked.

Personally, it’s saved me in so many situations with payload issues, so I always try it first when formatting goes weird. Just wanted to help reinforce it for the user :+1:

Totally get that, no worries at all :clap:t2:

2 Likes

Perfect. Thank you all

1 Like

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