JSON parameter need to be an valid JSON

Hello, what’s up?

In my workflow there is a problem in the node http request in the construction of the json, although the json is correct (I already tested it in postman and it worked) it returns: ERROR: JSON parameter needs to be a valid JSON.

I realized that it only returns this error when there are expressions in the body and I don’t know how to get around it

{
  "meta": {
    "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6"
  },
  "nodes": [
    {
      "parameters": {
        "content": "## I walk with an expression on my body",
        "height": 284,
        "width": 370
      },
      "id": "bd159966-bfa7-4eb0-8ee7-aad6fc40f05f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1360,
        440
      ]
    },
    {
      "parameters": {},
      "id": "c5603439-8a66-43b1-b005-3f6d4f1600b7",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        660,
        540
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://webhook.site/eee7361a-f28d-46ed-bfb3-61357221096e",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer test"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"emission\": \"2023-12-26T16:32:02.462Z\",\n  \"status\": \"COMMITTED\",\n  \"customer_id\": \"9eefa81d-756a-4629-9ba0-0578b573cbf1\",\n  \"products\": [\n    {\n      \"description\": \"plano pró anual\\ncondição especial com parcelamento em 6 vezes.\",\n      \"product_id\":\"d9a8526b-30e1-455b-8b19-898e03b27085\",\n      \"quantity\": 1,\n      \"value\": 4950\n    }\n  ],\n  \"payment\": {\n    \"type\": \"TIMES\",\n    \"method\": \"BANKING_BILLET\",\n    \"installments\": [\n    {\"number\": 1, \"value\": 825, \"duedate\": \"2023-12-20\", \"status\": \"PENDING\"},{\"number\": 2, \"value\": 825, \"duedate\": \"2024-01-20\", \"status\": \"PENDING\"},{\"number\": 3, \"value\": 825, \"duedate\": \"2024-02-20\", \"status\": \"PENDING\"},{\"number\": 4, \"value\": 825, \"duedate\": \"2024-03-20\", \"status\": \"PENDING\"},{\"number\": 5, \"value\": 825, \"duedate\": \"2024-04-20\", \"status\": \"PENDING\"},{\"number\": 6, \"value\": 825, \"duedate\": \"2024-05-20\", \"status\": \"PENDING\"}\n    ]\n  }\n}",
        "options": {}
      },
      "id": "0e3757e0-7336-46b0-8aa8-69c746c554ee",
      "name": "Criar cobrança parcelada2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        860,
        860
      ]
    },
    {
      "parameters": {
        "operation": "concatenateItems",
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "c3b59168-ec53-44d4-a649-4a3256adf09b",
      "name": "Juntas as parcelas",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 3.1,
      "position": [
        860,
        540
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://webhook.site/eee7361a-f28d-46ed-bfb3-61357221096e",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer test"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"emission\": \"2023-12-26T16:32:02.462Z\",\n  \"status\": \"COMMITTED\",\n  \"customer_id\": \"9eefa81d-756a-4629-9ba0-0578b573cbf1\",\n  \"products\": [\n    {\n      \"description\": \"plano pró anual\\ncondição especial com parcelamento em 6 vezes.\",\n      \"product_id\":\"d9a8526b-30e1-455b-8b19-898e03b27085\",\n      \"quantity\": 1,\n      \"value\": 4950\n    }\n  ],\n  \"payment\": {\n    \"type\": \"TIMES\",\n    \"method\": \"BANKING_BILLET\",\n    \"installments\": [\n  {{ $node[\"Juntas as parcelas\"].json }}\n    ]\n  }\n}",
        "options": {}
      },
      "id": "c2d9e5ea-c0f9-43c6-b6d1-633836280dba",
      "name": "Criar cobrança parcelada",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1180,
        540
      ]
    },
    {
      "parameters": {
        "content": "## Expressionless body walk",
        "height": 284,
        "width": 370
      },
      "id": "9762a145-00a9-4d51-9d41-7590322bc25b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1320,
        860
      ]
    },
    {
      "parameters": {
        "content": "## Webhook test site: https://webhook.site/",
        "width": 458
      },
      "id": "e283a055-edcc-4b1e-bc50-6174abcf1410",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        780,
        280
      ]
    }
  ],
  "connections": {
    "When clicking \"Execute Workflow\"": {
      "main": [
        [
          {
            "node": "Juntas as parcelas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Juntas as parcelas": {
      "main": [
        [
          {
            "node": "Criar cobrança parcelada",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Juntas as parcelas": [
      {
        "data": [
          {
            "number": 1,
            "value": 825,
            "duedate": "2023-12-20",
            "status": "PENDING"
          },
          {
            "number": 2,
            "value": 825,
            "duedate": "2024-01-20",
            "status": "PENDING"
          },
          {
            "number": 3,
            "value": 825,
            "duedate": "2024-02-20",
            "status": "PENDING"
          },
          {
            "number": 4,
            "value": 825,
            "duedate": "2024-03-20",
            "status": "PENDING"
          },
          {
            "number": 5,
            "value": 825,
            "duedate": "2024-04-20",
            "status": "PENDING"
          },
          {
            "number": 6,
            "value": 825,
            "duedate": "2024-05-20",
            "status": "PENDING"
          }
        ]
      }
    ]
  }
}```

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

versão n8n: 1.20.0
Base de dados: postgres
n8n EXECUTIONS_PROCESS: modo de fila
Executando o n8n via: docker

I had the same problem today. It turned out to be related to unescaped special characters, a quick JSON.stringify seemed to fix it.

2 Likes

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