Having issue with JSON

Hey there! Im having issues with a JSON that keeps being flagged as invalid. Part of it is dynamic coming from a set node, and the issue is somewhere in it. I removed it and tried with a ‘test’ and it worked. Though its dynamic the format will remain the same but with different data, so finding the problem and fixing it should do it.

Heres the JSON

{
  "subscriber_id": {{$json.subscriber_id}},
  "data": {
    "version": "v2",
    "content": {
      "type": "whatsapp",
      "messages": [
        {
          "type": "text",
          "text": "{{ $('Extract Task Details7').item.json.message }}"
        }
      ]
    }
  },
  "message_tag": "ACCOUNT_UPDATE"
}

“{{ $(‘Extract Task Details7’).item.json.message }}” is where I get the issue, and here is an example of it from the set node output:

[

{

"message": "Cidade de Origem: brasilia\nCidade de Destino: catatau\nData de Ida: 10/09/2025\nData de Volta: 12/09/2035\nPreferência de bairro para hotel: Somente viagem, sem hotel\n\n\n---\n\n Aqui está a lista de opções com cada hotel seguido pelo seu respectivo quarto:\n\n1. Hotel Fusion Hplus EXPRESS - Quarto Duplo Casal com Cozinha\n2. Hotel Cullinan Hplus PREMIUM - Quarto Executivo Duplo com Vista Cidade\n3. Hotel Comfort Suites Brasília - LUXO QUEEN\n4. Hotel Metropolitan Hotel Brasília - SUITE SUPERIOR QUEEN NÃO FUMANTE\n5. Hotel RAMADA BY WYNDHAM BRASILIA ALVORADA - EXECUTIVO QUEEN BED\n"

}

]

Any help is appreciated. I THINK it has something to do with the line breaks (\n) but removing them screws the formatting and since this is sent to whatsapp they dont read
.

Hello @Joao_Victor and welcome to the community!

Have you tried wrapping that dynamic value in JSON.stringify()? That might properly escape the line breaks and ensure your JSON remains valid.

1 Like

That worked, thanks!

1 Like

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